[PATCH] D32346: [clang-tidy] New readability check for strlen argument
Jonas Toth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 25 03:52:53 PDT 2017
JonasToth added a comment.
> #include <string.h>
> void dostuff(const char *P) {
>
> if (strncmp(P+2,"xyz",3)==0) {}
>
> }
>
>
Iam not super familiar with C, but the intend of the function is to check the following:
P = "foxyz", P2 = "abxyz", P3 = "opxyz", ...
And if P matches this kind of string pattern.
> /home/danielm/strlen.c:3:16: warning: strlen() argument has pointer addition, it is recommended to subtract the result instead. [readability-strlen-argument]
>
> if (strncmp(P+2,"xyz",3)==0) {}
> ^
>
>
Why is it matched? This is the code transformation from -O2? I dont know a way to surround that, and i think you should not call clang-tidy with optimization.
> I should probably avoid these, I guess skipping all warnings in macro code sounds ok to me.
You can check if the code is a result of macro expansion, i think that would be enough.
Repository:
rL LLVM
https://reviews.llvm.org/D32346
More information about the cfe-commits
mailing list