]> granicus.if.org Git - yasm/commitdiff
Clean up expect_() in both parsers. In the nasm parser we were passing a
authorPeter Johnson <peter@tortall.net>
Sun, 13 May 2007 19:55:54 +0000 (19:55 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 13 May 2007 19:55:54 +0000 (19:55 -0000)
raw string as a printf string which could have resulted in a random memory
access.

svn path=/trunk/yasm/; revision=1839

modules/parsers/gas/gas-parse.c
modules/parsers/nasm/nasm-parse.c

index 6ed0212f7c381ff4b4dcf30dc8a783a62acfefec..ff78f9e76743b8481ea5cd83e425b68e19fe81b1 100644 (file)
@@ -143,26 +143,26 @@ demand_eol_(yasm_parser_gas *parser_gas)
 static int
 expect_(yasm_parser_gas *parser_gas, int token)
 {
-    static char strch[] = "expected ` '";
+    static char strch[] = "` '";
     const char *str;
 
     if (curtok == token)
         return 1;
 
     switch (token) {
-        case INTNUM:            str = "expected integer"; break;
-        case FLTNUM:            str = "expected floating point value"; break;
-        case STRING:            str = "expected string"; break;
-        case INSN:              str = "expected instruction"; break;
-        case PREFIX:            str = "expected instruction prefix"; break;
-        case REG:               str = "expected register"; break;
-        case REGGROUP:          str = "expected register group"; break;
-        case SEGREG:            str = "expected segment register"; break;
-        case TARGETMOD:         str = "expected target modifier"; break;
-        case LEFT_OP:           str = "expected <<"; break;
-        case RIGHT_OP:          str = "expected >>"; break;
-        case ID:                str = "expected identifier"; break;
-        case LABEL:             str = "expected label"; break;
+        case INTNUM:            str = "integer"; break;
+        case FLTNUM:            str = "floating point value"; break;
+        case STRING:            str = "string"; break;
+        case INSN:              str = "instruction"; break;
+        case PREFIX:            str = "instruction prefix"; break;
+        case REG:               str = "register"; break;
+        case REGGROUP:          str = "register group"; break;
+        case SEGREG:            str = "segment register"; break;
+        case TARGETMOD:         str = "target modifier"; break;
+        case LEFT_OP:           str = "<<"; break;
+        case RIGHT_OP:          str = ">>"; break;
+        case ID:                str = "identifier"; break;
+        case LABEL:             str = "label"; break;
         case LINE:
         case DIR_ALIGN:
         case DIR_ASCII:
@@ -182,14 +182,14 @@ expect_(yasm_parser_gas *parser_gas, int token)
         case DIR_SECTNAME:
         case DIR_SKIP:
         case DIR_ZERO:
-            str = "expected directive";
+            str = "directive";
             break;
         default:
-            strch[10] = token;
+            strch[1] = token;
             str = strch;
             break;
     }
-    yasm_error_set(YASM_ERROR_PARSE, str);
+    yasm_error_set(YASM_ERROR_PARSE, "expected %s", str);
     destroy_curtok();
     return 0;
 }
index 311057e46773d12e0b1e254eb21ca46d35212b7a..d3ddbb3e27d0d97fa7a0b624aab54a71e0131422 100644 (file)
@@ -139,48 +139,48 @@ demand_eol_(yasm_parser_nasm *parser_nasm)
 static int
 expect_(yasm_parser_nasm *parser_nasm, int token)
 {
-    static char strch[] = "expected ` '";
+    static char strch[] = "` '";
     const char *str;
 
     if (curtok == token)
         return 1;
 
     switch (token) {
-        case INTNUM:            str = "expected integer"; break;
-        case FLTNUM:            str = "expected floating point value"; break;
-        case DIRECTIVE_NAME:    str = "expected directive name"; break;
-        case FILENAME:          str = "expected filename"; break;
-        case STRING:            str = "expected string"; break;
-        case SIZE_OVERRIDE:     str = "expected size override"; break;
-        case DECLARE_DATA:      str = "expected DB/DW/etc."; break;
-        case RESERVE_SPACE:     str = "expected RESB/RESW/etc."; break;
-        case INCBIN:            str = "expected INCBIN"; break;
-        case EQU:               str = "expected EQU"; break;
-        case TIMES:             str = "expected TIMES"; break;
-        case SEG:               str = "expected SEG"; break;
-        case WRT:               str = "expected WRT"; break;
-        case NOSPLIT:           str = "expected NOSPLIT"; break;
-        case STRICT:            str = "expected STRICT"; break;
-        case INSN:              str = "expected instruction"; break;
-        case PREFIX:            str = "expected instruction prefix"; break;
-        case REG:               str = "expected register"; break;
-        case SEGREG:            str = "expected segment register"; break;
-        case TARGETMOD:         str = "expected target modifier"; break;
-        case LEFT_OP:           str = "expected <<"; break;
-        case RIGHT_OP:          str = "expected >>"; break;
-        case SIGNDIV:           str = "expected //"; break;
-        case SIGNMOD:           str = "expected %%"; break;
-        case START_SECTION_ID:  str = "expected $$"; break;
-        case ID:                str = "expected identifier"; break;
-        case LOCAL_ID:          str = "expected .identifier"; break;
-        case SPECIAL_ID:        str = "expected ..identifier"; break;
-        case LINE:              str = "expected %line"; break;
+        case INTNUM:            str = "integer"; break;
+        case FLTNUM:            str = "floating point value"; break;
+        case DIRECTIVE_NAME:    str = "directive name"; break;
+        case FILENAME:          str = "filename"; break;
+        case STRING:            str = "string"; break;
+        case SIZE_OVERRIDE:     str = "size override"; break;
+        case DECLARE_DATA:      str = "DB/DW/etc."; break;
+        case RESERVE_SPACE:     str = "RESB/RESW/etc."; break;
+        case INCBIN:            str = "INCBIN"; break;
+        case EQU:               str = "EQU"; break;
+        case TIMES:             str = "TIMES"; break;
+        case SEG:               str = "SEG"; break;
+        case WRT:               str = "WRT"; break;
+        case NOSPLIT:           str = "NOSPLIT"; break;
+        case STRICT:            str = "STRICT"; break;
+        case INSN:              str = "instruction"; break;
+        case PREFIX:            str = "instruction prefix"; break;
+        case REG:               str = "register"; break;
+        case SEGREG:            str = "segment register"; break;
+        case TARGETMOD:         str = "target modifier"; break;
+        case LEFT_OP:           str = "<<"; break;
+        case RIGHT_OP:          str = ">>"; break;
+        case SIGNDIV:           str = "//"; break;
+        case SIGNMOD:           str = "%%"; break;
+        case START_SECTION_ID:  str = "$$"; break;
+        case ID:                str = "identifier"; break;
+        case LOCAL_ID:          str = ".identifier"; break;
+        case SPECIAL_ID:        str = "..identifier"; break;
+        case LINE:              str = "%line"; break;
         default:
-            strch[10] = token;
+            strch[1] = token;
             str = strch;
             break;
     }
-    yasm_error_set(YASM_ERROR_PARSE, str);
+    yasm_error_set(YASM_ERROR_PARSE, "expected %s", str);
     destroy_curtok();
     return 0;
 }