From: Steven Rostedt <rostedt@goodmis.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Mark Rutland <mark.rutland@arm.com>,
Artem Sadovnikov <a.sadovnikov@ispras.ru>
Subject: Re: [GIT PULL] ftrace: Changes for v6.17
Date: Thu, 31 Jul 2025 07:53:18 -0400 [thread overview]
Message-ID: <20250731075318.45a2f84d@gandalf.local.home> (raw)
In-Reply-To: <CAHk-=wh+h2WR6f2g+3HyLD1Zjg-fXC8yOE5bQmetrPvWHCU-2w@mail.gmail.com>
On Wed, 30 Jul 2025 16:15:21 -0700
Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Tue, 29 Jul 2025 at 11:42, Steven Rostedt <rostedt@goodmis.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
next prev parent reply other threads:[~2025-07-31 11:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 18:42 Steven Rostedt
2025-07-30 23:15 ` Linus Torvalds
2025-07-31 11:53 ` Steven Rostedt [this message]
2025-07-31 11:55 ` Steven Rostedt
2025-07-31 0:35 ` pr-tracker-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250731075318.45a2f84d@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=a.sadovnikov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®