[PATCH] D26646: Avoid calling std::memcmp with nullptr

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 15:55:00 PST 2016


zturner added inline comments.


================
Comment at: include/llvm/ADT/StringSwitch.h:76
+    assert(N);
+    assert(S[N-1] == '\0');
     if (!Result && N-1 == Str.size() &&
----------------
I don't think this second assert is valid.  Consider this code:

```
char dir[MAX_PATH];
sprintf(dir, "%s/%s", parent, child);
auto X = StringSwitch<int>(MyPath).Case(dir, 1);
```

There is no guarantee what is the value of `S[N-1]`


https://reviews.llvm.org/D26646





More information about the llvm-commits mailing list