gpt4 book ai didi

c++ - Lex 解析器 : (end of buffer or a NUL) segfault

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:00:59 26 4
gpt4 key购买 nike

我编写的 lex 解析器一直遇到段错误问题。因此,在构建我的程序时,我在 Makefile 中添加了调试开关 -d。这是我从中得到的输出。

--accepting rule at line 180 ("bxz")
--accepting rule at line 61 (" ")
--accepting rule at line 180 ("e")
--accepting rule at line 68 ("
")
--accepting rule at line 180 ("0L")
--accepting rule at line 193 ("!")
--accepting rule at line 68 ("
")
--accepting rule at line 180 ("0x")
--accepting rule at line 193 (""")
--accepting rule at line 68 ("
")
--(end of buffer or a NUL)
Segmentation fault

当我通过调试工具运行它时,我发现错误发生在 yy_get_next_buffer () at lex.yy.c:1324,这是从我手写的 lex 文件自动生成的 C 文件。我该如何解决这个问题?提前致谢。

最佳答案

(我将其标记为“不可复制”,however it timed-out/aged awayIt has been answered in the comments 。)

@LokiAstari 写道:

It is unlikely that the bug is in the lex code. Therefore it sounds like you are writing off the end of a buffer or abusing memory incorrectly in some other way. Valgrind may help in finding memory errors

@AK 写道:

try to put a newline after your last tokenstring. It might be that your parser tries to find some terminating character after the last symbol.

@ChrisDodd 写道:

You've probably corrupted flex's internal buffer pointer somehow, by writing off the end of an array or some such. If you look at the lex code that is crashing, you might be able to put a data breakpoint on the datastructure that has the incorrect data and figure out who is modifying it

关于c++ - Lex 解析器 : (end of buffer or a NUL) segfault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7060993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com