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.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
For a generic tool, this seems to be an okay fix; however, this is an API test driver. I would like to hear from other reviewers as to whether there is an intent to test the API for the AttrCount == 0 case. If there is, then I believe that allocation should not be attempted, and the API should work with a null pointer.
Comment Actions
To preserve exercising of the list getter when the count is zero, I suggest:
int AttrCount = /*...*/; LLVMAttributeRef *Attrs = 0; if (AttrCount) { Attrs = /*...*/; assert(Attrs); } LLVMGet/*...*/; free(Attrs);
Even on systems where malloc(0) does not return a null pointer, the getter functions could not have safely accessed an object via said pointer.