gpt4 book ai didi

mysql - 夹板和 MySQL : Null storage passed as non-null param

转载 作者:行者123 更新时间:2023-11-29 12:47:59 26 4
gpt4 key购买 nike

我尝试将 Splint 与简短的 CGI 脚本一起使用,但出现此错误:

空存储作为非空参数传递:mysql_init(NULL)

mysql_init 被定义为如果参数为 NULL 则返回新值,如果不是则将结果存储在参数中。然而,如果我尝试

MYSQL* connection;
mysql_init(connection);

我会得到:

定义之前使用的变量连接

如何解决这个问题?一种方法当然是注释mysql.h,这样 Splint 就不会提示。是我唯一的解决方案吗?

最佳答案

您可以编辑 mysql.h 将该参数注释为 /*@null@*/,或者停用该特定代码行的警告 :

/*@-nullpass@*/
connection = mysql_init(NULL);
/*@=nullpass@*/

顺便说一句,请注意不要将未初始化的变量传递给函数:

MYSQL* connection; /* this pointer contains garbage at this point */
mysql_init(connection); /* this may get a segmentation fault */

相反,你应该这样做:

MYSQL* connection = NULL; /* initialize to NULL */
connection = mysql_init(connection); /* get a hold of the new object created */

关于mysql - 夹板和 MySQL : Null storage passed as non-null param,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25179289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com