[pacman-dev] [PATCH] libalpm: Do a sanity check before manipulating final DB URL

Allan McRae allan at archlinux.org
Sun Apr 19 11:38:24 UTC 2015


On 19/04/15 00:25, Martti Kühne wrote:
> On Thu, Apr 16, 2015 at 9:36 PM, Florian Pritz <bluewind at xinu.at> wrote:
>>
>> Comment changed, but not the code? If you know where that + 9 comes from
>> it might be a good idea to replace it with strlen("whatever") which the
>> compile should optimize out later, but writing it this way makes the
>> whole thing a lot clearer.
> 
> 
> Do the pacman developers trust the compiler with optimizing strlen()?

Yes - we let compliers do their job, which they are remarkably good at.

> Because there's sizeof which does a perfectly predictable (off-by-one)
> job using but an operator for measuring the length of a string
> constant. Furthermore it does so without implying the compiler would
> sidestep the standard library's work in a way or another... Who says
> you can't have a libc "obscurelibc" that does something else there?

Many standards ensure that strlen() does what it should.

> A preprocessor macro branching on (#x == '"') or (sizeof(x) ==
> sizeof(char*)) would be the less beautiful alternative, but I think
> I'm risking to be yelled back at that way. :-)

The risk is strong!


More information about the pacman-dev mailing list