[llvm-commits] [llvm] r46781 - /llvm/trunk/include/llvm/ADT/StringMap.h

Anton Korobeynikov asl at math.spbu.ru
Tue Feb 5 15:34:41 PST 2008


Author: asl
Date: Tue Feb  5 17:34:40 2008
New Revision: 46781

URL: http://llvm.org/viewvc/llvm-project?rev=46781&view=rev
Log:
Don't dereference an invalid pointer if string is empty.

Modified:
    llvm/trunk/include/llvm/ADT/StringMap.h

Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=46781&r1=46780&r2=46781&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Tue Feb  5 17:34:40 2008
@@ -273,7 +273,7 @@
     return find(Key, Key + strlen(Key));
   }
   iterator find(const std::string &Key) {
-    const char* key_start = &Key[0];
+    const char* key_start = (Key.empty() ? NULL : &Key[0]);
     return find(key_start, key_start + Key.size());
   }
 
@@ -286,7 +286,7 @@
     return find(Key, Key + strlen(Key));
   }
   const_iterator find(const std::string &Key) const {
-    const char* key_start = &Key[0];
+    const char* key_start = (Key.empty() ? NULL : &Key[0]);
     return find(key_start, key_start + Key.size());
   }
 
@@ -295,7 +295,7 @@
     return entry.getValue();
   }
   ValueTy& operator[](const std::string &Key) {
-    const char* key_start = &Key[0];
+    const char* key_start = (Key.empty() ? NULL : &Key[0]);
     value_type& entry = GetOrCreateValue(key_start, key_start + Key.size());
     return entry.getValue();
   }
@@ -307,7 +307,7 @@
     return count(Key, Key + strlen(Key));
   }
   size_type count(const std::string &Key) const {
-    const char* key_start = &Key[0];
+    const char* key_start = (Key.empty() ? NULL : &Key[0]);
     return count(key_start, key_start + Key.size());
   }
 





More information about the llvm-commits mailing list