summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-c-test
diff options
context:
space:
mode:
authorAndus Yu <andusyllvm@gmail.com>2019-07-04 14:36:34 +0000
committerAndus Yu <andusyllvm@gmail.com>2019-07-04 14:36:34 +0000
commit7aff852810d363378009fec3486486931e43c034 (patch)
treea9212244d432db7532b510d1e9850d888c24ea04 /llvm/tools/llvm-c-test
parent0810f16fb9e89e9d7809a0e9a9a7296b35f8ef27 (diff)
downloadbcm5719-llvm-7aff852810d363378009fec3486486931e43c034.tar.gz
bcm5719-llvm-7aff852810d363378009fec3486486931e43c034.zip
llvm-c-test avoid calling malloc(0)
Summary: As explained in D63668, malloc(0) could return a null pointer. llvm-c-test does not handle this case correctly. Instead of calling malloc(0), avoid the operation altogether. Authored By: andusy Reviewers: hubert.reinterpretcast, xingxue, jasonliu, daltenty, cebowleratibm Reviewed By: hubert.reinterpretcast Subscribers: mehdi_amini, dexonsmith, jsji, llvm-commits Tags: LLVM Differential Revision: https://reviews.llvm.org/D63788 llvm-svn: 365144
Diffstat (limited to 'llvm/tools/llvm-c-test')
-rw-r--r--llvm/tools/llvm-c-test/attributes.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/llvm/tools/llvm-c-test/attributes.c b/llvm/tools/llvm-c-test/attributes.c
index 826cb094e22..487769f94db 100644
--- a/llvm/tools/llvm-c-test/attributes.c
+++ b/llvm/tools/llvm-c-test/attributes.c
@@ -29,9 +29,12 @@ int llvm_test_function_attributes(void) {
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 @@ int llvm_test_callsite_attributes(void) {
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);
}
OpenPOWER on IntegriCloud