[compiler-rt] r266388 - Fix StaticAnalyzer complaints. NFC.

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 16:58:26 PDT 2016


Author: gbiv
Date: Thu Apr 14 18:58:26 2016
New Revision: 266388

URL: http://llvm.org/viewvc/llvm-project?rev=266388&view=rev
Log:
Fix StaticAnalyzer complaints. NFC.

Clang's StaticAnalyzer seems to (correctly) complain about code like:

    T *p = calloc(sizeof(U), N);

...Where T and U are different types.

This patch removes some instances of this pattern from compiler-rt.

Patch by Apelete Seketeli.
Differential Revision: http://reviews.llvm.org/D19085

Modified:
    compiler-rt/trunk/lib/builtins/emutls.c

Modified: compiler-rt/trunk/lib/builtins/emutls.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/emutls.c?rev=266388&r1=266387&r2=266388&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/emutls.c (original)
+++ compiler-rt/trunk/lib/builtins/emutls.c Thu Apr 14 18:58:26 2016
@@ -164,12 +164,14 @@ emutls_get_address_array(uintptr_t index
     emutls_address_array* array = pthread_getspecific(emutls_pthread_key);
     if (array == NULL) {
         uintptr_t new_size = emutls_new_data_array_size(index);
-        array = calloc(new_size + 1, sizeof(void*));
+        array = malloc(new_size * sizeof(void *) + sizeof(emutls_address_array));
+        if (array)
+            memset(array->data, 0, new_size * sizeof(void*));
         emutls_check_array_set_size(array, new_size);
     } else if (index > array->size) {
         uintptr_t orig_size = array->size;
         uintptr_t new_size = emutls_new_data_array_size(index);
-        array = realloc(array, (new_size + 1) * sizeof(void*));
+        array = realloc(array, new_size * sizeof(void *) + sizeof(emutls_address_array));
         if (array)
             memset(array->data + orig_size, 0,
                    (new_size - orig_size) * sizeof(void*));




More information about the llvm-commits mailing list