且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果一个人抱怨得到(),为什么不跟scanf函数相同(QUOT;%S" ...)?

更新时间:2022-12-09 11:50:18

答案很简单,没​​有人写了code在GCC产生的警告。

The answer is simply that no-one has written the code in GCC to produce that warning.

正如您所指出的,为%S的特定情况下的警告(没有字段宽度)是比较合适的。

As you point out, a warning for the specific case of "%s" (with no field width) is quite appropriate.

但是,请记住,这仅仅是为的情况下,scanf()的情况下 vscanf()的fscanf() vfscanf()。此格式说明可与 sscanf的绝对安全()页vsscanf(),因此,警告不应发出这种情况下。这意味着,你不能简单地把它添加到现有的scanf函数式格式字符串分析code;你必须是分成的fscanf风格的格式字符串和sscanf的样式格式字符串的选项。

However, bear in mind that this is only the case for the case of scanf(), vscanf(), fscanf() and vfscanf(). This format specifier can be perfectly safe with sscanf() and vsscanf(), so the warning should not be issued in that case. This means that you cannot simply add it to the existing "scanf-style-format-string" analysis code; you will have to split that into "fscanf-style-format-string" and "sscanf-style-format-string" options.

我敢肯定,如果你生产的GCC的最新版本补丁它代表的被接受(当然,你将需要提交补丁glibc的头文件也是如此)的好机会。

I'm sure if you produce a patch for the latest version of GCC it stands a good chance of being accepted (and of course, you will need to submit patches for the glibc header files too).