[PATCH] D63788: llvm-c-test avoid calling malloc(0)

Andus Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 08:13:53 PDT 2019


andusy updated this revision to Diff 207068.
andusy added a comment.

Update to call `LLVMGetAttributesAtIndex` even when `AttrCount` is 0.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63788/new/

https://reviews.llvm.org/D63788

Files:
  llvm/tools/llvm-c-test/attributes.c


Index: llvm/tools/llvm-c-test/attributes.c
===================================================================
--- llvm/tools/llvm-c-test/attributes.c
+++ llvm/tools/llvm-c-test/attributes.c
@@ -29,9 +29,12 @@
     for (Idx = LLVMAttributeFunctionIndex, ParamCount = LLVMCountParams(F);
          Idx <= ParamCount; ++Idx) {
       int AttrCount = LLVMGetAttributeCountAtIndex(F, Idx);
-      LLVMAttributeRef *Attrs =
-          (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef));
-      assert(Attrs);
+      LLVMAttributeRef *Attrs = 0;
+      if (AttrCount) {
+        Attrs =
+            (LLVMAttributeRef *)malloc(AttrCount * sizeof(LLVMAttributeRef));
+        assert(Attrs);
+      }
       LLVMGetAttributesAtIndex(F, Idx, Attrs);
       free(Attrs);
     }
@@ -61,9 +64,12 @@
               ParamCount = LLVMCountParams(F);
                Idx <= ParamCount; ++Idx) {
             int AttrCount = LLVMGetCallSiteAttributeCount(I, Idx);
-            LLVMAttributeRef *Attrs = (LLVMAttributeRef *)malloc(
-                AttrCount * sizeof(LLVMAttributeRef));
-            assert(Attrs);
+            LLVMAttributeRef *Attrs = 0;
+            if (AttrCount) {
+              Attrs = (LLVMAttributeRef *)malloc(
+                  AttrCount * sizeof(LLVMAttributeRef));
+              assert(Attrs);
+            }
             LLVMGetCallSiteAttributes(I, Idx, Attrs);
             free(Attrs);
           }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63788.207068.patch
Type: text/x-patch
Size: 1432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190628/29816068/attachment.bin>


More information about the llvm-commits mailing list