1. 最近遇到的问题,格式化输出的时候遇到了一个错误

char test = -106;
Report("test tlv:%d,%d,%d,%d",*o_val,(signed char)*o_val,test,(signed char)test);

看下report函数底层的代码

char log_pc_buff[128] = {0};
int Report(const char *pcFormat, ...)
{
    int iRet = 0;
    char *pcBuff, *pcTemp;
    int iSize = 512;
    va_list list;
    pcBuff = log_pc_buff;
    if(pcBuff == NULL)
    {
        return -1;
    }
    while(1)
    {
        va_start(list,pcFormat);
        iRet = vsnprintf(pcBuff,iSize,pcFormat,list);
        va_end(list);

输出的结果

test tlv:155,-101,150,-106

总结起来,底层的vsnprintf函数,如果不强制转换成有符号,那么就会出问题。

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2021-05-30
  • 2022-01-14
  • 2021-11-05
  • 2022-12-23
  • 2022-01-10
  • 2021-11-04
猜你喜欢
  • 2021-06-27
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
相关资源
相似解决方案