我正在用 C 语言做一个关于 AVL 树的学校项目。代码出现以下错误。它编译得很好,但它以
Segmentation fault (core dumped)
终止。
==210456== Invalid read of size 8
==210456== at 0x1095B5: rotate_left (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x10968C: rotate_double_right (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109C6E: treat_shrink_left (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109DBC: remove_leftmost_son (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109E15: actual_remove (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x10A098: remove_info (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109FB6: remove_info (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x10A31E: main (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== Address 0x18 is not stack'd, malloc'd or (recently) free'd
==210456==
==210456==
==210456== Process terminating with default action of signal 11 (SIGSEGV)
==210456== Access not within mapped region at address 0x18
==210456== at 0x1095B5: rotate_left (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x10968C: rotate_double_right (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109C6E: treat_shrink_left (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109DBC: remove_leftmost_son (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109E15: actual_remove (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x10A098: remove_info (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x109FB6: remove_info (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== by 0x10A31E: main (in /home/asteria/Documents/MC202/MC202_024/lab05/main)
==210456== If you believe this happened as a result of a stack
==210456== overflow in your program's main thread (unlikely but
==210456== possible), you can try to increase the size of the
==210456== main thread stack using the --main-stacksize= flag.
==210456== The main thread stack size used in this run was 8388608.
我需要弄清楚这一点,但我正在挣扎。有人可以帮忙吗?
谢谢你! :)
这是典型的访问违规,表明您正在尝试从非法地址读取 8 个字节。 使用-g参数来编译你的程序:
gcc <yourappsource> -g <other compiler parameters your compiler needs>
这将显示 valgrind 中的行号,您可以调查指针操作是否有任何越界或错误。