[llvm-commits] [llvm] r155661 - /llvm/trunk/runtime/libprofile/CommonProfiling.c

Ted Kremenek kremenek at apple.com
Thu Apr 26 13:54:27 PDT 2012


Author: kremenek
Date: Thu Apr 26 15:54:27 2012
New Revision: 155661

URL: http://llvm.org/viewvc/llvm-project?rev=155661&view=rev
Log:
Defensively guard against calling malloc() with a size of zero.

Modified:
    llvm/trunk/runtime/libprofile/CommonProfiling.c

Modified: llvm/trunk/runtime/libprofile/CommonProfiling.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/runtime/libprofile/CommonProfiling.c?rev=155661&r1=155660&r2=155661&view=diff
==============================================================================
--- llvm/trunk/runtime/libprofile/CommonProfiling.c (original)
+++ llvm/trunk/runtime/libprofile/CommonProfiling.c Thu Apr 26 15:54:27 2012
@@ -65,6 +65,15 @@
   for (Length = 0, i = 0; i != (unsigned)argc; ++i)
     Length += strlen(argv[i])+1;
 
+  // Defensively check for a zero length, even though this is unlikely
+  // to happen in practice.  This avoids calling malloc() below with a
+  // size of 0.
+  if (Length == 0) {
+    SavedArgs = 0;
+    SavedArgsLength = 0;
+    return argc;
+  }
+  
   SavedArgs = (char*)malloc(Length);
   for (Length = 0, i = 0; i != (unsigned)argc; ++i) {
     unsigned Len = strlen(argv[i]);





More information about the llvm-commits mailing list