snprintf在Linux版本上给出了错误 [英] snprintf is giving error on Linux build
问题描述
大家好,
当我在Linux上使用以下代码时,构建失败并出现以下错误。
你能不能让我知道LInux上这个用法有什么问题。
/usr/include/bits/stdio2.h:66: 44:错误:调用int __builtin ___ snprintf_chk(char *,unsigned int,int,unsigned int,const char *,...)将始终溢出目标缓冲区链接CXX共享库
snprintf(formatStr, sizeof (result), < span class =code-string> %% 0%ullX,precision);
感谢您的帮助。
谢谢,
Sudhakar
我认为使用snprintf是错误。请参阅此处: snprintf [ ^ ]
第一个参数是buffer,第二个参数是第一个参数的大小(缓冲区大小) 。
它应该像
snprintf(结果,sizeof(结果),%% 0%ullX ,精确度);
我尝试了以下示例,没关系。
#include< stdio.h>
int main(){
int 一世;
char buff [ 100 ];
i = snprintf(buff, sizeof (buff), %d, 10 );
if (i> 0)
buff [i] = 0 ;
printf( %s%d,buff,i);
return 0 ;
}
但我不确定你的格式字符串是否正确(%% 0%ullX)
Hi All,
when I am using below code on Linux the build is failing with the below error .
Could you please let me know what could be wrong with this usage on LInux.
/usr/include/bits/stdio2.h:66:44: error: call to int __builtin___snprintf_chk(char*, unsigned int, int, unsigned int, const char*, ...) will always overflow destination buffer Linking CXX shared library
snprintf(formatStr,sizeof(result),"%%0%ullX", precision);
Appreciate your help.
Thanks,
Sudhakar
I think usage of snprintf is wrong. see here: snprintf[^]
the first parameter is buffer, the second parameter is the size of the first parameter(buffer size).
It should be like
snprintf(result,sizeof(result),"%%0%ullX", precision);
I tried the following example and it is OK.
#include <stdio.h> int main() { int i; char buff[100]; i=snprintf(buff, sizeof(buff), "%d", 10); if(i>0) buff[i]=0; printf("%s %d", buff, i); return 0; }
But I am not sure if your format string is correct ("%%0%ullX")
这篇关于snprintf在Linux版本上给出了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!