Posts Tagged ‘ splint

狗屁splint,折腾死我了

偶尔看到一个下载管理工具uget觉得挺好玩的,就弄了一个svn版本的准备玩玩。突发奇想想实践一下静态检查,索性祭出splint。惨痛的经历就这样开始了。

1.

mars@mars-laptop:~/memoryleaktest/urlget/trunk/src$ splint ug_plugin_curl.c 
Splint 3.1.2 --- 03 May 2009
 
ug_plugin_curl.c:38: Include file  matches the name of a POSIX
    library, but the POSIX library is not being used.  Consider using +posixlib
    or +posixstrictlib to select the POSIX library, or -warnposix to suppress
    this message.
  Header name matches a POSIX header, but the POSIX library is not selected.
  (Use -warnposixheaders to inhibit warning)
ug_plugin_curl.c:43:26: Cannot find include file glib/gstdio.h on search path:
                           /usr/include;/usr/include
  Preprocessing error. (Use -preproc to inhibit warning)
ug_plugin_curl.c:44:29: Cannot find include file ug_plugin_curl.h on search
                           path: /usr/include;/usr/include
ug_plugin_curl.c:45:31: Cannot find include file ug_data_download.h on search
                           path: /usr/include;/usr/include
ug_plugin_curl.c:46:23: Cannot find include file ug_stdio.h on search path:
                           /usr/include;/usr/include
ug_plugin_curl.c:47:23: Cannot find include file ug_utils.h on search path:
                           /usr/include;/usr/include
ug_plugin_curl.c:48:21: Cannot find include file ug_uri.h on search path:
                           /usr/include;/usr/include
Preprocessing error for file: /home/mars/memoryleaktest/urlget/trunk/src/ug_plug
                           in_curl.c
*** Cannot continue.

看来是没有加载必要的头文件,翻看了一下源码文件夹应该在include 中,添加上

2.

mars@mars-laptop:~/memoryleaktest/urlget/trunk/src$ splint -I../include \
 ug_plugin_curl.c
Splint 3.1.2 --- 03 May 2009
 
ug_plugin_curl.c:38: Include file  matches the name of a POSIX
    library, but the POSIX library is not being used.  Consider using +posixlib
    or +posixstrictlib to select the POSIX library, or -warnposix to suppress
    this message.
  Header name matches a POSIX header, but the POSIX library is not selected.
  (Use -warnposixheaders to inhibit warning)
ug_plugin_curl.c:43:26: Cannot find include file glib/gstdio.h on search path:
                           ../include;/usr/include;/usr/include
  Preprocessing error. (Use -preproc to inhibit warning)
../include/ug_plugin.h:43:19: Cannot find include file glib.h on search path:
                                 ../include;/usr/include;/usr/include
   In file included from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_dataset.h:47:19: Cannot find include file glib.h on search path:
                                  ../include;/usr/include;/usr/include
   In file included from ../include/ug_plugin.h:44,
                 from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_data.h:45:19: Cannot find include file glib.h on search path:
                               ../include;/usr/include;/usr/include
   In file included from ../include/ug_dataset.h:48,
                 from ../include/ug_plugin.h:44,
                 from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_markup.h:43:19: Cannot find include file glib.h on search path:
                                 ../include;/usr/include;/usr/include
   In file included from ../include/ug_data.h:46,
                 from ../include/ug_dataset.h:48,
                 from ../include/ug_plugin.h:44,
                 from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_data_download.h:61:19: Cannot find include file glib.h on search
    path: ../include;/usr/include;/usr/include
   In file included from ../include/ug_plugin_curl.h:52,
                 from ug_plugin_curl.c:44
../include/ug_stdio.h:50: Include file  matches the name of a POSIX
    library, but the POSIX library is not being used.  Consider using +posixlib
    or +posixstrictlib to select the POSIX library, or -warnposix to suppress
    this message.
../include/ug_stdio.h:53: Include file  matches the name of a POSIX
    library, but the POSIX library is not being used.  Consider using +posixlib
    or +posixstrictlib to select the POSIX library, or -warnposix to suppress
    this message.
../include/ug_stdio.h:55: Include file  matches the name of a POSIX
    library, but the POSIX library is not being used.  Consider using +posixlib
    or +posixstrictlib to select the POSIX library, or -warnposix to suppress
    this message.
../include/ug_stdio.h:58:19: Cannot find include file glib.h on search path:
                                ../include;/usr/include;/usr/include
   In file included from ug_plugin_curl.c:46
../include/ug_stdio.h:59:26: Cannot find include file glib/gstdio.h on search
                                path: ../include;/usr/include;/usr/include
../include/ug_utils.h:40:19: Cannot find include file glib.h on search path:
                                ../include;/usr/include;/usr/include
   In file included from ug_plugin_curl.c:47
../include/ug_utils.h:41:26: Cannot find include file glib/gstdio.h on search
                                path: ../include;/usr/include;/usr/include
../include/ug_uri.h:40:19: Cannot find include file glib.h on search path:
                              ../include;/usr/include;/usr/include
   In file included from ug_plugin_curl.c:48
Preprocessing error for file: /home/mars/memoryleaktest/urlget/trunk/src/ug_plug
                              in_curl.c
*** Cannot continue.

哦,原来找不到glib头文件。靠,还没装glib的库和头文件,安装一下,对了把curl的库也一同装上。为了避免太多低质量的提示使用 +posixlib参数。

3.

mars@mars-laptop:~/memoryleaktest/urlget/trunk/src$ splint -I../include \
 ug_plugin_curl.c +posixlib
Splint 3.1.2 --- 03 May 2009
 
ug_plugin_curl.c:43:26: Cannot find include file glib/gstdio.h on search path:
                           ../include;/usr/include;/usr/include
  Preprocessing error. (Use -preproc to inhibit warning)
../include/ug_plugin.h:43:19: Cannot find include file glib.h on search path:
                                 ../include;/usr/include;/usr/include
   In file included from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_dataset.h:47:19: Cannot find include file glib.h on search path:
                                  ../include;/usr/include;/usr/include
   In file included from ../include/ug_plugin.h:44,
                 from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_data.h:45:19: Cannot find include file glib.h on search path:
                               ../include;/usr/include;/usr/include
   In file included from ../include/ug_dataset.h:48,
                 from ../include/ug_plugin.h:44,
                 from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_markup.h:43:19: Cannot find include file glib.h on search path:
                                 ../include;/usr/include;/usr/include
   In file included from ../include/ug_data.h:46,
                 from ../include/ug_dataset.h:48,
                 from ../include/ug_plugin.h:44,
                 from ../include/ug_plugin_curl.h:51,
                 from ug_plugin_curl.c:44
../include/ug_data_download.h:61:19: Cannot find include file glib.h on search
    path: ../include;/usr/include;/usr/include
   In file included from ../include/ug_plugin_curl.h:52,
                 from ug_plugin_curl.c:44
../include/ug_stdio.h:58:19: Cannot find include file glib.h on search path:
                                ../include;/usr/include;/usr/include
   In file included from ug_plugin_curl.c:46
../include/ug_stdio.h:59:26: Cannot find include file glib/gstdio.h on search
                                path: ../include;/usr/include;/usr/include
../include/ug_utils.h:40:19: Cannot find include file glib.h on search path:
                                ../include;/usr/include;/usr/include
   In file included from ug_plugin_curl.c:47
../include/ug_utils.h:41:26: Cannot find include file glib/gstdio.h on search
                                path: ../include;/usr/include;/usr/include
../include/ug_uri.h:40:19: Cannot find include file glib.h on search path:
                              ../include;/usr/include;/usr/include
   In file included from ug_plugin_curl.c:48
Preprocessing error for file: /home/mars/memoryleaktest/urlget/trunk/src/ug_plug
                              in_curl.c
*** Cannot continue.

啊,这是为什么阿,为什么?!看看/usr/include下面有没有 glib.h,果然没有。原来glib头文件在/usr/include/glib-2.0里面。于是乎添加一个目录啊。
4.

mars@mars-laptop:~/memoryleaktest/urlget/trunk/src$ splint -I../include \
 -I/usr/include/glib-2.0 ug_plugin_curl.c +posixlib
Splint 3.1.2 --- 03 May 2009
 
/usr/include/glib-2.0/glib/garray.h:50:9:
Parse Error. (For help on parse errors, see splint -help parseerrors.)
*** Cannot continue.

不是吧,这么牛逼的头文件居然无法解析。简直就是开玩笑嘛。google一下关键词“splint glib parse error”得到非常多不靠谱的答案,不过在这个网址http://www.cs.virginia.edu/pipermail/splint- discuss/2008-February/001110.html
有这样一段话

I compile a more elaborate, but very similar file perfectly using the make command in my working directory, so I went to check what I might be forgetting, only to find `pkg-config –cflags glib-2.0` hidden in my make file’s CFLAGS variable. Splint passes -I to the preprocessor, and the above backtick expression evaluates to “-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include” on my system.

貌似添加一个地址是不对的。那就添加两个好了。

5.

mars@mars-laptop:~/memoryleaktest/urlget/trunk/src$ splint -I../include \
 `pkg-config --cflags glib-2.0`  ug_plugin_curl.c +posixlib
Splint 3.1.2 --- 03 May 2009
 
ug_plugin_curl.c:91:75: Static supported_schemes[4] initialized to null value:
                           supported_schemes[4] = NULL
  A reference with no null annotation is assigned or initialized to NULL.  Use
  /*@null@*/ to declare the reference as a possibly null pointer. (Use
  -nullassign to inhibit warning)
ug_plugin_curl.c:96:2: Static plugin_class_curl.reserve initialized to null
                          value: plugin_class_curl.reserve = NULL
ug_plugin_curl.c:97:24: Initial value of plugin_class_curl.instance_size is
                           type size_t, expects guint: sizeof(UgPluginCurl)
  Types are incompatible. (Use -type to inhibit warning)
ug_plugin_curl.c:99:2: Static plugin_class_curl.file_types initialized to null
                          value: plugin_class_curl.file_types = NULL
ug_plugin_curl.c:113:42: Storage plugin_class_curl reachable from initial value
                            is unqualified static (should be unqualified)
  Storage derivable from a parameter does not match the alias kind expected for
  the formal parameter. (Use -compmempass to inhibit warning)
 
.....
.....
.....
 
ug_plugin_curl.c:756:58: Null storage passed as non-null param:
                            g_filename_from_utf8 (..., NULL)
ug_plugin_curl.c:760:16: Fresh storage file not released before return
   ug_plugin_curl.c:756:2: Fresh storage file created
/usr/include/bits/confname.h:31:27: *** Internal Bug at cscannerHelp.c:2428:
    Unexpanded macro not function or constant: int _PC_MAX_CANON [errno: 25]
     *** Please report bug to submit@bugs.debian.org (via reportbug) ***
       (attempting to continue, results may be incorrect)
/usr/include/bits/confname.h:32:1: Parse Error: Non-function declaration:
    _PC_MAX_CANON : int. (For help on parse errors, see splint -help
    parseerrors.)
*** Cannot continue.

问题是发现了不少,可是怎么又在系统文件上出了问题啊。google一下,找到答案http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473595
原来这的确是一个bug,由于splint在07年以后就没有更新过,所以应该是所有版本都会受到影响的吧。只要去掉 +posixlib就能正常工作了。
6.

mars@mars-laptop:~/memoryleaktest/urlget/trunk/src$ splint -I../include \
 `pkg-config --cflags glib-2.0`  ug_plugin_curl.c
Splint 3.1.2 --- 03 May 2009
 
ug_plugin_curl.c:38: Include file  matches the name of a POSIX
    library, but the POSIX library is not being used.  Consider using +posixlib
    or +posixstrictlib to select the POSIX library, or -warnposix to suppress
    this message.
  Header name matches a POSIX header, but the POSIX library is not selected.
  (Use -warnposixheaders to inhibit warning)
 
.....
.....
.....
 
ug_plugin_curl.c:760:16: Fresh storage file not released before return
   ug_plugin_curl.c:756:2: Fresh storage file created
 
Finished checking --- 179 code warnings

终于成功了。总结一下,想当然以为添加了/usr/include/glib-2.0就能行。结果差点把自己搞死,本来用splint的人就少,像我这样乱用的人就更少了。