[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wjWosrcv2=6m-=YgXRKev=5cnCg-1EhqDpbRXT5z6eQmg@mail.gmail.com>
Date: Fri, 16 Jul 2021 11:45:57 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Chuck Lever <chuck.lever@...cle.com>
Subject: Re: [GIT PULL] tracing: histogram fix and take 2 on the
__string_len() marcros
On Fri, Jul 16, 2021 at 11:37 AM Steven Rostedt <rostedt@...dmis.org> wrote:
>
>
> So how do you want this implemented?
>
> #define __assign_str_len(dst, src, len) \
> do { \
> strscpy(__get_str(dst), (src) ? (const char *)(src) : "(null)", len); \
> __get_str(dst)[len] = '\0';
What? That "__get_str(dst)[len] = '\0';" is pointless and wrong.
That's the _point_. strscpy() does the whole NUL termination
correctly, in ways that strncpy() never ever did.
But I also want to know what the actual _semantics_ of the source is.
Your "memcpy()" example implies that the source is always a fixed-size
thing. In that case, maybe that's the rigth thing to do, and you
should just create a real function for it.
So two choices:
(a) either just plain strscpy() works (or, if you want NUL padding,
use strscpy_pad()).
(b) you have very odd source/destination semantics, and it should be
its own function that explains it.
Note how in neither case is it ok to just make random inline code with
no explanations for the odd crazy code. Make a function that actually
describes what you want, documents it, and be done with it.
strncpy() is garbage. It should never be used in new code.
And random semantics that are undocumented and just implemented as a
illegible mess in a header file is not ok either.
Linus
Powered by blists - more mailing lists