LeetCode各种报错的含义

    技术2024-03-30  82

    1.Char 5: fatal error: control may reach end of non-void function [-Wreturn-type] }

    2.AddressSanitizer: heap-buffer-overflow on address 0x602000000040 at pc 0x000000406b5e bp 0x7ffc15cc0320 sp 0x7ffc15cc0318

    3.error: bad operand types for binary operator ‘&’

    4.terminate called after throwing an instance of ‘std::out_of_range’ what(): basic_string::substr

    5.AddressSanitizer:DEADLYSIGNAL

    6.member access within null pointer of type ‘TreeNode’

    1.Char 5: fatal error: control may reach end of non-void function [-Wreturn-type] }

    这类报错的含义是:没有考虑所有可能的返回值情况

    什么意思呢,比如我们的Java程序的一个方法:

    public int fun(int a) { if(a>0) return 1 else if(a<0) return -1; }

    那么如果我们的a==0那么就没有返回值,所以本方法没有考虑返回值情况

    2.AddressSanitizer: heap-buffer-overflow on address 0x602000000040 at pc 0x000000406b5e bp 0x7ffc15cc0320 sp 0x7ffc15cc0318

    本类报错意思是:检查了是否存在内存非法访问 就比如数组越界

    3.error: bad operand types for binary operator '&'

    博主的代码是这样的

    if(num&1==1)

    博主以为&的优先级比“==”大,实际上恰好相反,所以导致出错

    4.terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr

    解决方案:查找substr方法前后代码,排除可能的越界条件。

    5.AddressSanitizer:DEADLYSIGNAL

    表示数组越界

    6.member access within null pointer of type 'TreeNode'

    表示未考虑参数空值异常

    博主会持续更新

    Processed: 0.031, SQL: 9