locking/lockdep: fix format-truncation compiler-warning
PATCH 1/1 locking/lockdep: fix format-truncation compiler-warning
Compiler: gcc x86_64 v13.2.1
Config: allyesconfig, "treat warnings as errors" unset
This fixes a warning emitted by gcc, stating the output may be truncated. The fix included increasing the buffer size to the one denoted by gcc.
--- kernel/locking/lockdep_proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep_proc.c +1 -1
@@ -440,7 +440,7 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr)static void seq_time (struct seq_file *m,s64 time) { -char num[15 ]; +char num[22 ];snprint_time (num,sizeof (num), time);seq_printf (m," %14s" , num);
Signature · 1 line
2.41.0
Quoted 6 lines · Lucy Mielke
Compiler: gcc
x86_64v13.2.1
Config: allyesconfig, "treat warnings as errors" unsetThis fixes a warning emitted by gcc, stating the output may be truncated. The fix included increasing the buffer size to the one denoted by gcc.
Mind including the output by GCC in the changelog?
kernel/locking/lockdep_proc.c static void snprint_time(char *buf, size_t bufsiz, s64 nr) · line 446
Quoted 7 lines
static void
seq_time(struct seq_file *m, s64 time){kernel/locking/lockdep_proc.c +1
-1-char num[15 ]; +char num[22 ];snprint_time (num,sizeof (num), time);seq_printf (m," %14s" , num);
Fun.
So this:
static void snprint_time(char *buf, size_t bufsiz, s64 nr)
{
s64 div;
s32 rem;
nr += 5; /* for display rounding */
div = div_s64_rem(nr, 1000, &rem);
snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
}... actually needs 21+1 bytes?
Which I suppose is true - longest s64 is "-9223372036854775808"-ish, which converted to the fixed-point float format above is "-9223372036854775.80":
21 bytes, plus termination is another byte: 22.
Maybe put this into the changelog too, instead of relying on magic GCC calculations only. :-)
Thanks,
Ingo
Am Thu, Oct 12, 2023 at 12:11:13AM +0200 schrieb Ingo Molnar:
Quoted 3 lines
Mind including the output by GCC in the changelog?
Sure, let me resend the patch then :)
Quoted 8 lines
... actually needs 21+1 bytes?
Which I suppose is true - longest s64 is "-9223372036854775808"-ish, which converted to the fixed-point float format above is "-9223372036854775.80":
21 bytes, plus termination is another byte: 22.Maybe put this into the changelog too, instead of relying on magic GCC calculations only. :-)
I can include it as well, of course!
Mit freundlichen Grüßen / Best regards,
Lucy