[PATCH] D26646: Avoid calling std::memcmp with nullptr
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 14 16:11:32 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL286910: Avoid calling std::memcmp with nullptr (authored by vitalybuka).
Changed prior to commit:
https://reviews.llvm.org/D26646?vs=77909&id=77912#toc
Repository:
rL LLVM
https://reviews.llvm.org/D26646
Files:
llvm/trunk/include/llvm/ADT/StringSwitch.h
Index: llvm/trunk/include/llvm/ADT/StringSwitch.h
===================================================================
--- llvm/trunk/include/llvm/ADT/StringSwitch.h
+++ llvm/trunk/include/llvm/ADT/StringSwitch.h
@@ -72,28 +72,31 @@
template<unsigned N>
LLVM_ATTRIBUTE_ALWAYS_INLINE
StringSwitch& Case(const char (&S)[N], const T& Value) {
+ assert(N);
if (!Result && N-1 == Str.size() &&
- (std::memcmp(S, Str.data(), N-1) == 0)) {
+ (N == 1 || std::memcmp(S, Str.data(), N-1) == 0)) {
Result = &Value;
}
return *this;
}
template<unsigned N>
LLVM_ATTRIBUTE_ALWAYS_INLINE
StringSwitch& EndsWith(const char (&S)[N], const T &Value) {
+ assert(N);
if (!Result && Str.size() >= N-1 &&
- std::memcmp(S, Str.data() + Str.size() + 1 - N, N-1) == 0) {
+ (N == 1 || std::memcmp(S, Str.data() + Str.size() + 1 - N, N-1) == 0)) {
Result = &Value;
}
return *this;
}
template<unsigned N>
LLVM_ATTRIBUTE_ALWAYS_INLINE
StringSwitch& StartsWith(const char (&S)[N], const T &Value) {
+ assert(N);
if (!Result && Str.size() >= N-1 &&
- std::memcmp(S, Str.data(), N-1) == 0) {
+ (N == 1 || std::memcmp(S, Str.data(), N-1) == 0)) {
Result = &Value;
}
return *this;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26646.77912.patch
Type: text/x-patch
Size: 1299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161115/9ef6eb01/attachment.bin>
More information about the llvm-commits
mailing list