On Fri, 12.07.13 18:09, Kay Sievers ([email protected]) wrote: > > On Fri, Jul 12, 2013 at 5:35 PM, Shawn Landden <[email protected]> wrote: > > as most (if not all) of the prefix strings are static, these will get > > forward constant propagation optimized into single memcmp() calls, which > > should be much better than the non-SIMD hand-rolled version. > > > -#define hasprefix(s, prefix) (memcmp(s, prefix, strlen(prefix)) == 0) > > +#define startswith(s, prefix) (memcmp(s, prefix, strlen(prefix)) == 0) > > What if 's' is shorter than 'prefix'? We should not access the > possibly uninitialized memory?
This is a good point. I figure memcmp() quits its loop early in such a case, so that it will only access one vector of potentially uninitialized memory at most. That is of course only if memcmp() compares things linearly from the beginning. If it compares from the end, then we might end up accessing not even uninitialized but even unmapped memory, which could trigger a segfault... I don't think memcmp() makes any guarantees on the direction, so maybe we should not use it after all? strncmp() should work however, I guess... Lennart -- Lennart Poettering - Red Hat, Inc. _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
