harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 9a66940d6bae9a415c1d06f4ea4cccec6f00e02e
parent 25a57362a5eb8133200ee712c9b7449a40a425ae
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat, 22 Jan 2022 23:41:28 -0500

emit.c: cast isprint parameter to unsigned char

From isprint(3p):
       The c argument is an int, the value of which the application
       shall ensure is a character representable as an unsigned char or
       equal to the value of the macro EOF. If the argument has any
       other value, the behavior is undefined.

It is undefined whether char is signed or unsigned by default. If
signed, the isprint call here would invoke undefined behavior, since the
argument may be sign-extended.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Msrc/emit.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/emit.c b/src/emit.c @@ -236,7 +236,8 @@ emit_data_string(const char *str, size_t sz, FILE *out) bool q = false; for (size_t i = 0; i < sz; ++i) { /* XXX: We could stand to emit less conservatively */ - if (!isprint(str[i]) || str[i] == '"' || str[i] == '\\') { + if (!isprint((unsigned char)(str[i])) || str[i] == '"' + || str[i] == '\\') { if (q) { q = false; fprintf(out, "\", ");