Re: [PATCH] git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 19, 2023, 13:36 UTC
- Message-ID
- <aa9e4e07-03d8-4f4e-a63c-f393e1b56c92@web.de>
- In-Reply-To
- <xmqqa5q7e00q.fsf@gitster.g>
Am 18.12.23 um 21:19 schrieb Junio C Hamano:
Show 12 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes: > >> Thanks for the comprehensive commit message, I agree that we'd be >> better off avoiding adding a fallback. The patch looks good, I did >> wonder if we really need to covert all of these functions for a >> test-balloon but the patch is still pretty small overall. > > I do have to wonder, though, if we want to be a bit more careful > than just blindly trusting the platform (i.e. <stdbool.h> might > exist and __STDC_VERSION__ may say C99, but under the hood their > implementation may be buggy and coerce the result of an assignment > of 2 to be different from assigning true).
We could add a compile-time check like below. I can't decide if this would be prudent or paranoid. It's cheap, though, so perhaps just add this tripwire for non-conforming compilers without making a judgement?
René
diff --git a/git-compat-util.h b/git-compat-util.h index 603c97e3b3..8212feaa37 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -705,7 +705,7 @@ static inline bool skip_prefix(const char *str, const char *prefix, { do { if (!*prefix) { - *out = str; + *out = str + BUILD_ASSERT_OR_ZERO((bool)1 == (bool)2); return true; } } while (*str++ == *prefix++);