遇到过几次错误,通过gdb来查看错误对战,发现错误居然是atoi调用出错,除非atoi(NULL) 才会报这种错误.说明 row[0]==NULL.

 


(gdb) bt #
0 0x00007f82c6629132 in ____strtoll_l_internal () from /lib64/libc.so.6 #1 0x00007f82c6625ee0 in atoi () from /lib64/libc.so.6 #2 0x0000000000438c7b in MySQL_Util::select_one ( sql_string=0x7f82c4544190 "select sum(pointcoupon_added) from tb_recharge_records where user_id=214873 and status=0 and method=0 ", get_data=0x7f82c4544598, length=4, data_type=MYSQL_INT, pmysql=0x7f82c4545210) at MySQL_Util.hpp:177

 

 好无语啊,SQL语句中包括 sum() max() count(),及时没有返回值,也会执行到 这里面:

            MYSQL_RES *res = NULL;
            MYSQL_ROW row = NULL;
            res=mysql_store_result(pmysql);
            if( (row=mysql_fetch_row(res) )!=NULL )
            {
                                  // atoi(row[0])
            }else{
                nReturn=MYSQL_SQL_FAILED;
            }
            mysql_free_result(res);
            row=NULL;

NULL也会返回一行记录,真是够恶心的啊!只能判断 if(row[0]!=NULL) XXX=atoi(row[0]);

或许 atoi重新定义下 就好了:

static inline int mystrlen(char *str){//const 
    if(str==NULL)
        return 0;
    else
        return strlen(str);
}
static inline int myatoi(char * str){
    if(str==NULL)
        return 0;
    else
        return atoi(str);
}

类似的还有strlen(NULL)也会报错,一起改了.

 

 

 

 

 

相关文章:

  • 2021-10-11
  • 2021-05-17
  • 2021-09-11
  • 2021-12-07
  • 2021-07-05
  • 2021-10-28
  • 2021-10-18
猜你喜欢
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-01-14
  • 2021-05-27
  • 2021-12-10
相关资源
相似解决方案