git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter
@ 2021-03-06  0:51 HG King via GitGitGadget
  2021-03-07 20:34 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: HG King via GitGitGadget @ 2021-03-06  0:51 UTC (permalink / raw)
  To: git; +Cc: HG King, HGimself

From: HGimself <hgmaxwellking@gmail.com>

Signed-off-by: HGimself <hgmaxwellking@gmail.com>
---
    fix: added new BANNED_EXPL macro for better error messages, has a par…
    
    
    Extend Banned Function Error Messages
    =====================================
    
    AS A NEWER USER, I WANT TO BE ABLE TO UNDERSTAND WHY CERTAIN FUNCTIONS
    ARE BANNED AS WELL AS KNOW WHAT FUNCTIONS TO USE INSTEAD.
    
    
    Changes
    =======
    
     * Added new macro named BANNED_EXPL(func, expl) which added the expl
       onto the error message
     * Used strcpy as an example

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-896%2FHGHimself%2Ffix%2Fadd-new-ban-macro-with-explanation-parameter-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-896/HGHimself/fix/add-new-ban-macro-with-explanation-parameter-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/896

 banned.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/banned.h b/banned.h
index 7ab4f2e49219..a19f0afeda79 100644
--- a/banned.h
+++ b/banned.h
@@ -9,9 +9,10 @@
  */
 
 #define BANNED(func) sorry_##func##_is_a_banned_function
+#define BANNED_EXPL(func, expl) sorry_##func##_is_a_banned_funcion_because_##expl##.
 
 #undef strcpy
-#define strcpy(x,y) BANNED(strcpy)
+#define strcpy(x,y) BANNED_EXPL(strcpy, buffer_overflow_risk)
 #undef strcat
 #define strcat(x,y) BANNED(strcat)
 #undef strncpy

base-commit: be7935ed8bff19f481b033d0d242c5d5f239ed50
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter
  2021-03-06  0:51 [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter HG King via GitGitGadget
@ 2021-03-07 20:34 ` Junio C Hamano
  2021-03-08 18:05   ` Taylor Blau
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2021-03-07 20:34 UTC (permalink / raw)
  To: HG King via GitGitGadget; +Cc: git, HG King

"HG King via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  #undef strcpy
> -#define strcpy(x,y) BANNED(strcpy)
> +#define strcpy(x,y) BANNED_EXPL(strcpy, buffer_overflow_risk)

That does not help programmers that much (the above does not say
what to use instead, for example), and the mechanism inherently
does not give you sufficient space to give helpful guidance.

Adding a comment around each of these definition may be OK.  Upon
seeing foo_is_a_banned_function, somebody new to the codebase would
look for where it is banned, and find the above, so that is a good
place to give guidance.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter
  2021-03-07 20:34 ` Junio C Hamano
@ 2021-03-08 18:05   ` Taylor Blau
  2021-03-08 18:30     ` Jeff King
  2021-03-08 18:41     ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Taylor Blau @ 2021-03-08 18:05 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: HG King via GitGitGadget, git, HG King

On Sun, Mar 07, 2021 at 12:34:57PM -0800, Junio C Hamano wrote:
> "HG King via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> >  #undef strcpy
> > -#define strcpy(x,y) BANNED(strcpy)
> > +#define strcpy(x,y) BANNED_EXPL(strcpy, buffer_overflow_risk)
>
> That does not help programmers that much (the above does not say
> what to use instead, for example), and the mechanism inherently
> does not give you sufficient space to give helpful guidance.

Trying to cram information like "why is this function unsafe?" and "what
function should I use instead?" seems ill-fitted to trying to a macro
which is supposed to have a field for each.

I'm certainly not opposed to making these banned functions clearer, but
I do not think that this is the way to do it.

> Adding a comment around each of these definition may be OK.  Upon
> seeing foo_is_a_banned_function, somebody new to the codebase would
> look for where it is banned, and find the above, so that is a good
> place to give guidance.

Perhaps, but all of this information is already covered accurately in
the patches that introduced each banned function. So I'm not sure that I
even agree that this information is difficult to discover to begin with,
but I may be biased.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter
  2021-03-08 18:05   ` Taylor Blau
@ 2021-03-08 18:30     ` Jeff King
  2021-03-08 18:41     ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2021-03-08 18:30 UTC (permalink / raw)
  To: Taylor Blau; +Cc: Junio C Hamano, HG King via GitGitGadget, git, HG King

On Mon, Mar 08, 2021 at 01:05:46PM -0500, Taylor Blau wrote:

> > Adding a comment around each of these definition may be OK.  Upon
> > seeing foo_is_a_banned_function, somebody new to the codebase would
> > look for where it is banned, and find the above, so that is a good
> > place to give guidance.
> 
> Perhaps, but all of this information is already covered accurately in
> the patches that introduced each banned function. So I'm not sure that I
> even agree that this information is difficult to discover to begin with,
> but I may be biased.

Yeah, certainly my intent when I introduced banned.h was that people
would get the full reasoning from the commit log. I figured Git
developers could run "git log -S" or "git blame".

I'm not opposed to comments if somebody wants to write them, but it's
not clear to whether people who are actively writing patches for Git
have actually run into this situation and been confused, or if this is
bikeshedding from the recent posting of banned.h on Hacker News. (Even
if it is the latter, I am OK taking a patch that adds comments; I just
doubt that it's a good use of anybody's time).

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter
  2021-03-08 18:05   ` Taylor Blau
  2021-03-08 18:30     ` Jeff King
@ 2021-03-08 18:41     ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2021-03-08 18:41 UTC (permalink / raw)
  To: Taylor Blau; +Cc: HG King via GitGitGadget, git, HG King

Taylor Blau <ttaylorr@github.com> writes:

>> Adding a comment around each of these definition may be OK.  Upon
>> seeing foo_is_a_banned_function, somebody new to the codebase would
>> look for where it is banned, and find the above, so that is a good
>> place to give guidance.
>
> Perhaps, but all of this information is already covered accurately in
> the patches that introduced each banned function. So I'm not sure that I
> even agree that this information is difficult to discover to begin with,
> but I may be biased.

To help those who are not yet familiar with this codebase but are
willing to learn, I tend to agree with you that it is a good idea
not to miss opportunities to encourage them to run "git blame" to
find out about the project history in the parts of the system that
pique their interest.  They will make more motivated contributors
who are invested in the project, if they stick around.

It would discourage and filter out "drive-by" contributors, though.

Somebody may not yet be interested enough to "git clone" us, but
happens to have an extract of distro source tarball and enough
motivation to try peeking and tweaking around.  To such a curious
developer, the "blame" information and log messages with the change
are not readily available, so there probably is some balance to be
struck.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-08 18:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-06  0:51 [PATCH] fix: added new BANNED_EXPL macro for better error messages, new parameter HG King via GitGitGadget
2021-03-07 20:34 ` Junio C Hamano
2021-03-08 18:05   ` Taylor Blau
2021-03-08 18:30     ` Jeff King
2021-03-08 18:41     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).