.splintrc预处理器指令-D中的WhiteSpaces

时间:2013-03-05 09:30:57

标签: debian whitespace preprocessor-directive splint secure-coding

我想在debian稳定的环境中对我的一些资源运行splint 我需要给出预处理器指令-DUINT16_T='unsigned short',因为我经常需要它。我想将它放在我的.splintrc文件中 从splint -DUINT16_T='unsigned short' mysource.c这样的命令行运行时,它运行良好。如果将此行移至我的.splintrc文件

-DUINT16_T='unsigned short'
-I/usr/local/include/

splint调用结果

Cannot list files in .splintrc files:
                                 short' (probable missing + or -)
  A flag is not recognized or used in an incorrect way (Use -badflag to inhibit
  warning)

有没有人有解决方案? (请不要别名。)

为了进行更深入的讨论,我将提供一个mnwe(最小的不工作示例)hello.c,这可能有所帮助:

#include <stdio.h>

int main (void)
{
  UINT16_T returnvalue=0;
  printf ("Hello, world!\n");
  return returnvalue;
}

命令gcc -DUINT16_T='unsigned short' hello.c运行正常 - splint -DUINT16_T='unsigned short' hello.c当然还有

Return value type unsigned short int does not match declared type
                 int: returnvalue

但是,我怎样才能将这个DEFINE包含在我的.splintrc

2 个答案:

答案 0 :(得分:1)

- 新答案 -

你所问的只是没有在夹板中实现。

如果你看一下rcfiles.c第124行中的夹板3.1.2 rcfiles_loadFile 函数

124          while ((c = *s) != '\0')
125             { /* remember to handle spaces and quotes in -D and -U ... */
126               if (escaped)
127                 {
128                   escaped = FALSE;
129                 }
130               else if (quoted)
131                 {
132                   if (c == '\\')
133                     {
134                       escaped = TRUE;
135                     }
136                   else if (c == '\"')
137                     {
138                       quoted = FALSE;
139                     }
140                   else
141                     {
142                       ;
143                     }
144                 }
145               else if (c == '\"')
146                 {
147                   quoted = TRUE;
148                 }
149               else
150                 {
151                  if (c == ' ' || c == '\t' || c == '\n')
152                    {
153                      /*@innerbreak@*/ break;
154                    }
155                }
156 
157               s++;
158               incColumn ();
159             }

您会看到第125行中的评论是您要求的TODO。

我将第151行更改为

151                  if (c == '\t' || c == '\n')

编译,运行然后你最小的不工作的例子(.splintrc中没有引号)正在通过测试而没有问题。

然而,这种修改有点粗糙,因为一些夹板单元测试失败了。

答案 1 :(得分:0)

使用双引号而不是单引号。

-DUINT16_T="unsigned short"