X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fshader%2Fgrammar%2Fgrammar.c;h=a9775961d3a6577654cc072c8f3e423847e578e6;hb=4af0d940a35536f096a9289470af0268a79402b3;hp=7f2ee42d21d7ba06ec26da8cbf955eff1822e8d5;hpb=a79d4e75c3f1da65a6f4d4d8d450ad96fa98767d;p=mesa.git diff --git a/src/mesa/shader/grammar/grammar.c b/src/mesa/shader/grammar/grammar.c index 7f2ee42d21d..a9775961d3a 100644 --- a/src/mesa/shader/grammar/grammar.c +++ b/src/mesa/shader/grammar/grammar.c @@ -260,6 +260,8 @@ first). */ +#include + static void mem_free (void **); /* @@ -2691,14 +2693,16 @@ fast_match (dict *di, const byte *text, int *index, rule *ru, int *_PP, bytepool if (status == mr_matched) { - if (sp->m_emits != NULL) - if (emit_push (sp->m_emits, _BP->_F + _P, text[ind - 1], save_ind, &ctx)) + if (sp->m_emits != NULL) { + const byte ch = (ind <= 0) ? 0 : text[ind - 1]; + if (emit_push (sp->m_emits, _BP->_F + _P, ch, save_ind, &ctx)) { free_regbyte_ctx_stack (ctx, *rbc); return mr_internal_error; } - _P = _P2; + } + _P = _P2; } /* if the rule operator is a logical or, we pick up the first matching specifier */ @@ -2797,10 +2801,16 @@ static void grammar_load_state_destroy (grammar_load_state **gr) } } + +static void error_msg(int line, const char *msg) +{ + fprintf(stderr, "Error in grammar_load_from_text() at line %d: %s\n", line, msg); +} + + /* the API */ - grammar grammar_load_from_text (const byte *text) { grammar_load_state *g = NULL; @@ -2809,13 +2819,16 @@ grammar grammar_load_from_text (const byte *text) clear_last_error (); grammar_load_state_create (&g); - if (g == NULL) + if (g == NULL) { + error_msg(__LINE__, ""); return 0; + } dict_create (&g->di); if (g->di == NULL) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2829,6 +2842,7 @@ grammar grammar_load_from_text (const byte *text) if (get_identifier (&text, &g->syntax_symbol)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } eat_spaces (&text); @@ -2848,6 +2862,7 @@ grammar grammar_load_from_text (const byte *text) if (get_identifier (&text, &symbol)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } eat_spaces (&text); @@ -2862,6 +2877,7 @@ grammar grammar_load_from_text (const byte *text) if (get_emtcode (&text, &ma)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2877,6 +2893,7 @@ grammar grammar_load_from_text (const byte *text) if (get_regbyte (&text, &ma)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2892,6 +2909,7 @@ grammar grammar_load_from_text (const byte *text) if (get_errtext (&text, &ma)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2905,12 +2923,14 @@ grammar grammar_load_from_text (const byte *text) if (g->di->m_string != NULL) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } if (get_identifier (&text, &g->string_symbol)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2927,6 +2947,7 @@ grammar grammar_load_from_text (const byte *text) if (get_rule (&text, &ru, g->maps, g->mapb)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2940,6 +2961,7 @@ grammar grammar_load_from_text (const byte *text) if (ma == NULL) { grammar_load_state_destroy (&g); + error_msg(__LINE__, ""); return 0; } @@ -2953,6 +2975,7 @@ grammar grammar_load_from_text (const byte *text) g->di->m_regbytes)) { grammar_load_state_destroy (&g); + error_msg(__LINE__, "update_dependencies() failed"); return 0; }