【leetcode报错】报错信息及原因记录
1. runtime error: reference binding to misaligned address 0xbebebebebebec0ba for type 'int', which req
这种情况一般为数组越界访问,可以检查一下函数开头是否加了特殊情况(数组为空、栈为空等)判断,避免在数组为空的情况下后续继续对其操作。
2. solution.c: In function ‘isValidSerialization’ Line 25: Char 1: error: control reaches end of non-void function [-Werror=return-type] [solution.c] } ^ cc1: some warnings being treated as errors
leetcod判题系统如果不是void类型的函数,需要在任何情况下都有返回值,例如不能把return写在循环里的if语句,即使每种情况都讨论了,也需要有一个默认的return语句(不经过任何循环if语句嵌套);
3. Line 15: Char 5: error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
同2,必须每中情况下都有返回值,补一个返回值即可。
4.Line 53: Char 16: runtime error: member access within null pointer of type 'ListNode' (solution.cpp)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:62:16
一般是引用了空指针,例如ListNode *pre
,pre=NULL
,但是却使用了pre->next
;
5.error: reference to non-static member function must be called
报错的字面意思:调用了非静态函数成员,但并不是通过类对象来调用的,因此可以把这个调用的函数改为静态函数,或者将这个函数定义在这个类之外;
6.Line 24: Char 33: runtime error: member access within null pointer of type 'TreeNode' (solution.cpp)SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:33:33
试图使用空指针,可能是树、链表,可以添加判断条件。