[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250731075318.45a2f84d@gandalf.local.home>
Date: Thu, 31 Jul 2025 07:53:18 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: LKML <linux-kernel@...r.kernel.org>, Masami Hiramatsu
<mhiramat@...nel.org>, Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Mark Rutland <mark.rutland@....com>, Artem Sadovnikov
<a.sadovnikov@...ras.ru>
Subject: Re: [GIT PULL] ftrace: Changes for v6.17
On Wed, 30 Jul 2025 16:15:21 -0700
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Tue, 29 Jul 2025 at 11:42, Steven Rostedt <rostedt@...dmis.org> wrote:
> >
> > In print_graph_proc() the pid_ptr string is of size 11, but the comment says
> > /* sign + log10(MAX_INT) + '\0' */ which is actually 12.
>
> Lol. Quoting the ancient Greeks: "Math is hard, let's go shopping".
>
> That said, the comment is garbage anyway.
>
> Because "sign + log10(MAX_INT) + '\0'" really is just 11 - if you
> round or truncate.
I'm confused, sizeof("-2147483648") is equal to 12.
$ echo '
#include <stdio.h>
int main (int argc, char **argv)
{
printf("%ld\n", sizeof("-2147483648"));
return 0;
}' > maxchar.c
$ gcc -o maxchar maxchar.c
$ ./maxchar
12
>
> So somebody may have actually done the math "correctly", but the math
> was just stated wrongly.
>
> Much better to actually write things out properly instead of trying to be fancy.
>
> Becasue might be more legible to actually write it out and let the
> compiler do things, ie just do
>
> // This includes the sign and the terminating '\0'
> #define MAX_INT_CHARACTERS sizeof("-2147483648")
>
> which doesn't require people to know - or think they know - logarithms.
Hmm, should we add that to a header file?
-- Steve
Powered by blists - more mailing lists