【问题标题】:WhiteSpaces in .splintrc preprocessor directive -D.splintrc 预处理器指令中的空白 -D
【发布时间】:2013-03-05 09:30:56
【问题描述】:

我想在 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 中?

【问题讨论】:

  • 我需要同样的东西,除了标志:“-Dbit=unsigned char”

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


【解决方案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 中不带引号)顺利通过测试。

但是这个修改有点粗糙,因为一些夹板单元测试失败了。

【讨论】:

  • 我试过了 - 你的文件运行良好 - 但试试 #include int main (void) { UINT16_T returnvalue=0; printf ("你好,世界!\n");返回返回值; } 那么你只会在运行中看到,因为没有使用定义。好难过。进一步的提示/想法?
【解决方案2】:

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

-DUINT16_T="unsigned short"

【讨论】:

  • 目前我不能尝试,但是看看评论stackoverflow.com/questions/15220228/…我认为双引号也行不通。
  • 该评论中的引用不适用于.splintrc。从源代码中可以看到字符串得到quoted'\"' char。
猜你喜欢
  • 2012-01-17
  • 1970-01-01
  • 2017-11-30
  • 2023-03-05
  • 1970-01-01
相关资源
最近更新 更多