git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Fix callsites of real_pathdup() that wanted it to die on error

From
René Scharfe <l.s.r@web.de>
Date
Mar 9, 2017, 16:33 UTC
Message-ID
<40b64644-f01c-d748-1cc3-8b3046be8a83@web.de>
In-Reply-To
<alpine.DEB.2.20.1703091221440.3767@virtualbox>
Am 09.03.2017 um 12:24 schrieb Johannes Schindelin:
Show 7 quoted lines
> While I would have agreed earlier that René's patch looks less intrusive,
> I have to point out that there would not have been any possible regression
> if the original patch had introduced the die_on_error parameter. It would
> have made the contract *obvious*.
>
> The nicer API made the contract unobvious, and that was the reason that
> the bug could hide.
You mean nicer in the sense of more forgiving, right?

The meaning of calls of a function with a die_on_error parameter are only obvious if at least the name of that parameter is known. A declaration without it would not suffice:

	char *real_pathdup(const char *, int);

There are two possibilities that can't be distinguished by looking at callers alone:

	char *real_pathdup(const char *path, int die_on_error);
	char *real_pathdup(const char *path, int gentle);
An enum can help, so that calls look something like this:
	copy_or_death = real_pathdup(path, DIE_ON_ERROR);
	copy = real_pathdup(path, IGNORE_ERRORS); if (copy) ...

For binary flags we can easily encode that information into the function names and thus simplify the API:

	copy_or_death = real_pathdup_or_die(path);
	copy = real_pathdup_gently(path); if (copy) ...

And we can drop the suffix of the variant used overwhelmingly often, but as you pointed out that relies on readers knowing that convention.

I'm sure Brandon will balance these concerns nicely in follow-up patches. ;)
René
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 7 of 10 in “Fix crashes due to real_pathdup() potentially returning NULL”
  1. 0/2 Fix crashes due to real_pathdup() potentially returning NULLJohannes Schindelin, Mar 8, 2017
  2. 2/2 Fix callsites of real_pathdup() that wanted it to die on errorJohannes Schindelin, Mar 8, 2017
  3. René ScharfeMar 8, 2017
  4. Brandon WilliamsMar 8, 2017
  5. Junio C HamanoMar 8, 2017
  6. Johannes SchindelinMar 9, 2017
  7. René ScharfeMar 9, 2017
  8. 1/2 Demonstrate NULL pointer access with invalid GIT_WORK_TREEJohannes Schindelin, Mar 8, 2017
  9. Jeff KingMar 8, 2017
  10. Johannes SchindelinMar 9, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.