argdist: Generated streq-helper to ignore null terminator
authorSasha Goldshtein <goldshtn@gmail.com>
Mon, 16 Jan 2017 18:38:30 +0000 (18:38 +0000)
committerSasha Goldshtein <goldshtn@gmail.com>
Tue, 17 Jan 2017 07:42:39 +0000 (07:42 +0000)
Oftentimes we want to use the STRCMP helper to compare strings that
are not null-terminated, e.g. in USDT probes this often happens.
Ignore the null terminator (i.e. loop until the last character
excluding the null terminator).

tools/argdist.py

index 3bcf43a..f6bb8bf 100755 (executable)
@@ -258,7 +258,7 @@ static inline bool %s(char const *ignored, char const *str) {
         char needle[] = %s;
         char haystack[sizeof(needle)];
         bpf_probe_read(&haystack, sizeof(haystack), (void *)str);
-        for (int i = 0; i < sizeof(needle); ++i) {
+        for (int i = 0; i < sizeof(needle)-1; ++i) {
                 if (needle[i] != haystack[i]) {
                         return false;
                 }