sprintf_s报错Buffer too small

 

 错误代码:

char output[3];        
char ddd = 0x92;
sprintf_s(output, 3, "%02x", ddd);            

char时0x92转换结果为ffffff92,上述代码改为下面就不会报错

char output[9];        
char ddd = 0x92;
sprintf_s(output, 9, "%02x", ddd);

char output[3];        
unsigned char ddd = 0x92;
sprintf_s(output, 3, "%02x", ddd);

 

posted @ 2024-03-07 23:51  kelvin_yan  阅读(62)  评论(0编辑  收藏  举报