Re: [RFC][PATCH] string.h: Add strncmp_prefix() helper macro

From: Joe Perches
Date: Wed Dec 19 2018 - 17:05:38 EST


On Wed, 2018-12-19 at 16:32 -0500, Bryana Rostedt wrote:
> a quick grep in the kernel tree found several
> (thousands!) of cases that use this construct. A quick grep also
> revealed that there's probably several bugs in that use case. Some are
> that people forgot the "- 1" (which I found) and others could be that
> the constant for the sizeof is different than the constant (although, I
> haven't found any of those, but I also didn't look hard).

Several dozen cases exist like strncmp(foo, "bar", 4)
where it might as well use strcmp instead.

And a few mismatches exist like:

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c:2285: if (!strncmp(opt, "eee_timer:", 6)) {
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c:318: if (!strncmp(s, "power", 9))
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c:321: if (!strncmp(s, "balance-power", 17))
j