Bas*_*ing 6 debian whitespace splint secure-coding preprocessor-directive
我想splint在debian稳定的环境中运行我的一些源代码.
我需要给出预处理器指令-DUINT16_T='unsigned short',因为我经常需要它.我想将它放在我的.splintrc文件中.
从命令行运行时,splint -DUINT16_T='unsigned short' mysource.c它运行良好.如果将此行移动到我的.splintrc文件中
-DUINT16_T='unsigned short'
-I/usr/local/include/
Run Code Online (Sandbox Code Playgroud)
该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)
Run Code Online (Sandbox Code Playgroud)
有人有解决方案吗?(请不要别名).
为了进行更深入的讨论,我将提供一个mnwe(最小的不工作示例)hello.c,这可能会有所帮助:
#include <stdio.h>
int main (void)
{
UINT16_T returnvalue=0;
printf ("Hello, world!\n");
return returnvalue;
}
Run Code Online (Sandbox Code Playgroud)
命令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
Run Code Online (Sandbox Code Playgroud)
但是,我怎么能把这个DEFINE包含在我的脑子里.splintrc呢?
--新答案--
你所问的只是没有在夹板中实现。
如果看rcfiles.c第124行中的splint 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 }
Run Code Online (Sandbox Code Playgroud)
您会看到第 125 行中的注释是您所询问内容的 TODO。
我将第 151 行更改为
151 if (c == '\t' || c == '\n')
Run Code Online (Sandbox Code Playgroud)
编译,运行,然后你的最小的不工作示例(.splintrc 中没有引号)就可以顺利通过测试。
然而,这种修改有点粗糙,因为一些夹板单元测试随后失败了。
| 归档时间: |
|
| 查看次数: |
215 次 |
| 最近记录: |