diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-22 18:51:59 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-06 11:53:17 -0600 |
commit | 24e5d0ec1219e2dbb4b9510ef20833092a2b3871 (patch) | |
tree | 01bbcc34c6190fa1c35b2625e9ba1744b1447606 /libfmt | |
parent | f09b7435b3a5222597d27238226d23ec0cbd5bd2 (diff) |
wip: Build with -Wconversionlukeshu/safe-conversion
I think this found a real bug in the dhcp packet parser.
I don't think anything called lib9p_str{,n}() values that could be big
enough, but their bounds-checking was broken.
Diffstat (limited to 'libfmt')
-rw-r--r-- | libfmt/quote.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/libfmt/quote.c b/libfmt/quote.c index c91e0b0..36e1556 100644 --- a/libfmt/quote.c +++ b/libfmt/quote.c @@ -99,7 +99,7 @@ static void libfmt_conv_quote(struct fmt_state *state) { switch (needs_quote(ch)) { case QUOTE_NONE: - fmt_state_putchar(state, ch); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, ch)); break; case QUOTE_SIMPLE: fmt_state_putchar(state, '\\'); @@ -128,14 +128,14 @@ static void libfmt_conv_quote(struct fmt_state *state) { case QUOTE_U8: fmt_state_putchar(state, '\\'); fmt_state_putchar(state, 'U'); - fmt_state_putchar(state, (ch >> 28) & 0xF); - fmt_state_putchar(state, (ch >> 24) & 0xF); - fmt_state_putchar(state, (ch >> 20) & 0xF); - fmt_state_putchar(state, (ch >> 16) & 0xF); - fmt_state_putchar(state, (ch >> 12) & 0xF); - fmt_state_putchar(state, (ch >> 8) & 0xF); - fmt_state_putchar(state, (ch >> 4) & 0xF); - fmt_state_putchar(state, (ch >> 0) & 0xF); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 28) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 24) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 20) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 16) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 12) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 8) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 4) & 0xF)); + fmt_state_putchar(state, LM_SAFEDOWNCAST(char, (ch >> 0) & 0xF)); break; } continue; |