[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4] cutils: Provide strchrnul
From: |
Keno Fischer |
Subject: |
Re: [Qemu-devel] [PATCH v4] cutils: Provide strchrnul |
Date: |
Mon, 11 Jun 2018 16:44:25 -0400 |
> Suggest return strchrnul("Hello World", 'W') != 6, to avoid worries
> about a sufficiently smart compilers optimizing out a call that would
> otherwise fail to link, say because headers don't match libraries.
I'm happy to do that, but then again, a sufficiently smart compiler might
constant fold this call entirely, so to be completely safe maybe we need
extern char *haystack;
extern char needle;
int main(void) { return strchrnul(haystack, needle) != 6; }
Though frankly if you're in a position for this to be a problem, you've
got bigger problems. Happy to change this though.
> Should this be named HAVE_STRCHRNUL? It's how it would be named with
> Autoconf...
Ok, I will rename this.
>> +const char *qemu_strchrnul(const char *s, int c)
>> +{
>> + const char *e = strchr(s, c);
>> + if (!e) {
>> + e = s + strlen(s);
>> + }
>> + return e;
>
> Stupidest solution that could possibly work. Okay :)
Well, it's the pattern that was used everywhere in place of this function,
so certainly from a commit factoring this seemed like the most sensible
thing to do.
> How did you find the spots to convert to strchrnul()?
I audited uses of `strchr` and checked for whether they were really doing
`strchrnul` (plus the one use case in code that used to only ever be compiled
on Linux).