yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
880 stars 112 forks source link

Lint with trace on error segfaults #246

Closed allenbarnett5 closed 1 year ago

allenbarnett5 commented 1 year ago

Hi: If my source input has a syntax error, then activating --trace in peglint results in a segfault. For example, the grammar: a <- 'a' and the input: b yields:

$ ./peglint --trace --source 'b' ./a.peg 
E 1*    ┌[a] #0
E 1 │┌LiteralString 'a' #1
L 1 │└x LiteralString #1
L 1 └x [a] #0
Segmentation fault (core dumped)

This is on Pop!_OS (which is currently mostly Ubuntu 22.04 LTS) with both GCC 11 and Clang-14. Although they are both using the same libstdc++-11 headers. The segfault is at line 442, but the actual error is buried deep in the unwinding code at the end of a lambda expression which starts at line 4681. For some reason, the compiler is overwriting the pointer "const char* s" in that lambda's cleanup!

This library is really great! So much easier to use than lex and yacc :-)

Thanks, Allen

yhirose commented 1 year ago

@allenbarnett5 thanks for the bug report! I'll take a look at it.

allenbarnett5 commented 1 year ago

I installed GCC 12 and its headers on my box and it works OK with that version.

yhirose commented 1 year ago

@allenbarnett5, I fixed it. Thank you for the fine contribution!

allenbarnett5 commented 1 year ago

Thanks for fixing this!