【问题标题】:Splint and MySQL: Null storage passed as non-null paramSplint 和 MySQL:空存储作为非空参数传递
【发布时间】:2014-08-07 09:47:28
【问题描述】:

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

Null storage passed as non-null param: mysql_init(NULL)

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

MYSQL* connection;
mysql_init(connection);

我会得到:

Variable connection used before definition

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

【问题讨论】:

    标签: mysql c splint


    【解决方案1】:

    您可以编辑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 */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多