看起来简单的代码,也不容易写对,一起来找找代码的茬


Linuxer

周期性发送Linux原创文章和招聘信息,沟通企业和Linux人才的总线(微信号:LinuxDev

关注

下面的代码存在各种各样的内存访问问题及违背“防御性编程”思想的地方,请用splint扫描这份代码,并修复其中*所有*的问题。


扫描方法:splint main.c +bounds +showconstraintlocation -mustfreefresh

#include <stdio.h>

#include <string.h>


char *get_pass(void)

{

    char password[10];

    scanf("%s\n", password);

    return password;

}


void echo_pass(char *str)

{

    char password[10];

    strcpy(password, get_pass());

    printf("%s\n", password);

}


int main(void)

{

    printf("Enter password:\n");

    echo_pass();


    return 0;

留言回复答案,最佳回答将获赠人民邮电出版社异步社区任意技术图书(随意选取)。