剑指 Offer 25. 合并两个排序的链表 - 力扣(LeetCode) (leetcode-cn.com)

目录

错误信息

AddressSanitizer

SEGV

From Cadence Community

From Wikipedia

调试与分析

未解决的疑问


错误信息

AddressSanitizer

AddressSanitizer is a fast memory error detector(内存错误探测器). It consists of a compiler instrumentation module (编译器检测模块)and a run-time library. The tool can detect the following types of bugs:
1. Out-of-bounds accesses to heap, stack and globals //堆、栈、全局变量越界访问
2. Use-after-free
3. Use-after-return
4. Use-after-scope //作用域外使用
5. Double-free, invalid free
6. Memory leaks (experimental)

SEGV

  • From Cadence Community

SEGV means "segmentation fault"(分段故障). It simply mean that the program is accessing a memory that it should not. This is due to software error, that lead to corrupted memory pointers, etc.Simply put, this error message is not useful to find the cause of the software crash.

  • From Wikipedia

In computing, a segmentation fault (often shortened to segfault) or access violation(访问冲突) is a fault, or failure condition, raised by hardware with memory protection, notifying an OS the software has attempted to access a restricted area of memory (a memory access violation). On stantard x86 computers, this is a form of general protection fault. The OS kernel will, in response, usually perform some corrective action(纠正措施), generally passing the fault on to the offending process by sending the process a signal. Process can in some cases install a custom signal handler(自定义信号处理程序), allowing them to recover on their own, but otherwise the OS default signal handler(操作系统默认信号处理程序) is used, generally causing abnormal termination(异常终止) of the process (a program crash), and sometimes a core dump(核心转储).

ABORTING:终止

调试与分析

class lst {ListNode* p;const ListNode* preHead;
public:lst() :p(new ListNode(0)), preHead(p) {}lst(ListNode* l) :p(l) {}~lst() {delete preHead;}ListNode* head() const {return preHead->next;}void operator++() {p = p->next;}lst operator++(int k) {ListNode* tmp = p;p = p->next;return tmp;}bool not_empty() {return p != NULL;}int _val() const {return p->val;}ListNode* ptr() const {return p;}void add(const lst L) {//参数也是局部变量,在函数结束之后,作为参数的对象会被析构p->next = L.ptr();p = p->next;    //*问题出在这里,这条语句应该去掉}bool compare(const lst& L) const {return this->_val() > L._val();}
};class Solution {
public:ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {lst L1(l1), L2(l2), iter;while (L1.not_empty() && L2.not_empty()) {iter.add(L2.compare(L1) ? L1++ : L2++);++iter;}iter.add(L1.not_empty() ? L1 : L2);return iter.head();}
};

调试过程中发现,每次执行完add函数之后,析构函数都会被调用一次。猜想应该是由于add函数传递的参数是对象而非对象的引用,作为函数内部局部变量的对象在函数调用完之后会被析构。

经过调试,发现错因是add函数的第二条语句"p = p->next"属实多余,不该出现在这个位置,去掉之后,顺利通过.

未解决的疑问

在原来的错误代码中,如果注释掉析构函数提交,会出现问题:

但是在修正之后,如果去掉析构函数,程序却能够顺利通过。不知道在错误代码中注释掉析构函数之后出现“超出时间限制”是何原因。

AddressSanitizer: DEADLYSIGNAL相关推荐

  1. LeetCode 报错AddressSanitizer: SEGV on unknown address 0x000000619d20 (pc 0x000000401a6a bp 0x7ffd35b3

    LeetCode90子集 II 题目描述: 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ ...

  2. Fuzz测试之libfuzzer高频报错问题FAQ

    Fuzz测试之libfuzzer高频报错问题FAQ 场景问题 报错解决 编译阶段 运行阶段 进阶资料 本文小结fuzz测试遇到的高频问题及其解答. 场景问题 Q:fuzz主调函数OneInput/In ...

  3. AddressSanitizer+cmake

    1. AddressSanitizer+cmake(Linux) 编译指令: CXXFLAGS通常需要加上 -fsanitize=address -fno-omit-frame-pointer #打印 ...

  4. C++ 内存泄漏检测:valgrind和AddressSanitizer

    推荐使用工具valgrind,安装: sudo apt install valgrind #debian/ubuntu 内存泄漏示例代码如下: /* code with memory leak */ ...

  5. Linux 下的 AddressSanitizer

    AddressSanitizer 是一个性能非常好的 C/C++ 内存错误探测工具.它由编译器的插桩模块(目前,LLVM 通过)和替换了 malloc 函数的运行时库组成.这个工具可以探测如下这些类型 ...

  6. 在Windows系统中配置Google AddressSanitizer

    Google AddressSanitizer简介 AddressSanitizer (ASan) 是 C 和 C++ 的内存错误检测软件,它可以检测: 释放指针后继续使用 堆缓冲区溢出 栈缓冲区溢出 ...

  7. valgrind 内存泄漏_应用 AddressSanitizer 发现程序内存错误

    应用 AddressSanitizer 发现程序内存错误 作为 C/ C++ 工程师,在开发过程中会遇到各类问题,最常见便是内存使用问题,比如,越界,泄漏.过去常用的工具是 Valgrind,但使用 ...

  8. 力扣报错“AddressSanitizer: heap-buffer-overflow on address...”的解决办法

    做力扣报了个错: AddressSanitizer: heap-buffer-overflow on address 0x6020000001cc at pc-- 大概意思 LeetCode使用了Ad ...

  9. AddressSanitizer 页面

    介绍 AddressSanitizer 是一个快速的内存错误检测工具,它由一个编译时插桩模块和一个运行库组成.该工具可以检测以下类型的错误: OOB(包括堆.栈和全局变量) UAF Use-After ...

最新文章

  1. 平衡二叉排序树的创建和实现调整过程
  2. JavaScript中函数文档注释
  3. CMA内存管理子系统
  4. 特征选择算法java实现_relief算法特征选择
  5. Linux日志出现大量kernel: NET: Registered protocol family 36
  6. java猜数游戏图形界面_Java做一个猜数的小游戏
  7. 统计list里面相同元素个数_LeetCode 第 347 号问题:前 K 个高频元素
  8. c/c++ 求字符数组长度(非所占内存大小)
  9. java开放地址法和链地址法解决hash冲突
  10. linux之at,crontab
  11. Python爬取猫眼电影排行榜并写入MySQL
  12. Java信息管理系统模板思维导图
  13. 使用VSCode运行C语言
  14. [转] 网卡超时实现机制 watchdog_timeo/ndo_tx_timeout
  15. 本地连接不通的情况下连接vmbox
  16. 如何处理CU2X0-2 (DP)变频器的F01910故障
  17. Java书写文字格斗游戏
  18. zemax模拟ld_使用ZEMAX 序列模式模拟激光二极管光源
  19. 电脑辐射,电脑辐射危害大 五妙招正确防辐射
  20. 爱弹幕服务器不稳定,最爱弹幕视频 现代Hold X绚丽动手玩

热门文章

  1. Android隐藏输入法自带的输入框,将输入框向上推
  2. Vue的脚手架工具cli安装
  3. java毕业设计创新学分认证系统mybatis+源码+调试部署+系统+数据库+lw
  4. 网络编程--初识网络
  5. http请求中的post和get到底是什么
  6. 数据库:主码、主属性、非主属性、候选码等关系,终于弄明白了
  7. Win7快捷键打开命令提示符
  8. 计算机ntc是什么功能,ntc是什么?
  9. matlab方程近似求根,matlab求解方程的几种方法
  10. 读书笔记之香帅中国财富报告