Commit f279e1d9167fc0dcc7172c8f845a253511ac6001
Committed by
Tom Rini
1 parent
eb5b63f369
Exists in
smarc_8mq_lf_v2020.04
and in
12 other branches
lib: errno: avoid error format-overflow
In cmd/regulator.c an error occurs with GCC 9.2.1 if CONFIG_ERRNO_STR is
not defined:
cmd/regulator.c: In function ‘failure’:
cmd/regulator.c:20:2: error: ‘%s’ directive argument is null
[-Werror=format-overflow=]
20 | printf("Error: %d (%s)\n", ret, errno_str(ret));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘constraint’,
inlined from ‘constraint’ at cmd/regulator.c:111:12:
cmd/regulator.c:115:3: error: ‘%s’ directive argument is null
[-Werror=format-overflow=]
115 | printf(" %s (err: %d)\n", errno_str(val), val);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
errno_str() should return a valid string instead of NULL if
CONFIG_ERRNO_STR is not defined.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Showing 1 changed file with 10 additions and 1 deletions Side-by-side Diff
include/errno.h
| ... | ... | @@ -12,12 +12,21 @@ |
| 12 | 12 | |
| 13 | 13 | #define __set_errno(val) do { errno = val; } while (0) |
| 14 | 14 | |
| 15 | +/** | |
| 16 | + * errno_str() - get description for error number | |
| 17 | + * | |
| 18 | + * @errno: error number (negative in case of error) | |
| 19 | + * Return: string describing the error. If CONFIG_ERRNO_STR is not | |
| 20 | + * defined an empty string is returned. | |
| 21 | + */ | |
| 15 | 22 | #ifdef CONFIG_ERRNO_STR |
| 16 | 23 | const char *errno_str(int errno); |
| 17 | 24 | #else |
| 25 | +static const char error_message[] = ""; | |
| 26 | + | |
| 18 | 27 | static inline const char *errno_str(int errno) |
| 19 | 28 | { |
| 20 | - return 0; | |
| 29 | + return error_message; | |
| 21 | 30 | } |
| 22 | 31 | #endif |
| 23 | 32 | #endif /* _ERRNO_H */ |