Fix error-related issues (#773)

* Mark `error` as a `format` function, to properly scan its format

* Fix the call to error() from parser.y:
  - Use '%s' to avoid passing an arbitrary format
  - Simplify yyerror overall

* Fix size parameter of %.*s format being an int... bonkers standard.

* Report the number of arguments required and provided on a STRFMT mismatch

* Add an assert to check for a very unlikely bug
This commit is contained in:
daid
2021-03-02 16:34:19 +01:00
committed by GitHub
parent 56071599e7
commit 5d6e0677d9
5 changed files with 17 additions and 24 deletions

View File

@@ -48,7 +48,7 @@ void processWarningFlag(char const *flag);
* Used to warn the user about problems that don't prevent the generation of
* valid code.
*/
void warning(enum WarningID id, const char *fmt, ...);
void warning(enum WarningID id, const char *fmt, ...) format_(printf, 2, 3);
/*
* Used for errors that compromise the whole assembly process by affecting the
@@ -57,7 +57,7 @@ void warning(enum WarningID id, const char *fmt, ...);
* It is also used when the assembler goes into an invalid state (for example,
* when it fails to allocate memory).
*/
_Noreturn void fatalerror(const char *fmt, ...);
_Noreturn void fatalerror(const char *fmt, ...) format_(printf, 1, 2);
/*
* Used for errors that make it impossible to assemble correctly, but don't
@@ -65,6 +65,6 @@ _Noreturn void fatalerror(const char *fmt, ...);
* get a list of all errors at the end, making it easier to fix all of them at
* once.
*/
void error(const char *fmt, ...);
void error(const char *fmt, ...) format_(printf, 1, 2);
#endif