soasme / PeppaPEG

PEG Parser in ANSI C
https://soasme.com/PeppaPEG
MIT License
55 stars 7 forks source link

Segfault when grammar entry rule doesn't exists #141

Closed mingodad closed 2 years ago

mingodad commented 2 years ago

Describe the bug Segfault when grammar entry rule doesn't exists

To Reproduce Steps to reproduce the behavior:

  1. Using the README json example execute peppa parse -G json.peg -e entry2 data.json
  2. See the segfault

Desktop (please complete the following information):

This seems to fix the problem (line numbers are from my code with other changes):

@@ -3194,9 +3330,9 @@ P4_GetErrorMessage(P4_Source* source) {
         return NULL;

     memset(source->errmsg, 0, sizeof(source->errmsg));
     sprintf(source->errmsg, "line %zu:%zu, expect %s",
             source->error.lineno, source->error.offset,
-            source->error.rule->name);
+            source->error.rule ? source->error.rule->name : source->entry_name);
soasme commented 2 years ago

Thanks for reporting the issue!