summaryrefslogtreecommitdiff
path: root/lib/builtins
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2016-04-14 23:58:26 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2016-04-14 23:58:26 +0000
commit64dbe06997a8d533adb94e6e9e5eca491a93181d (patch)
tree23285f668a48f1d2ac99ce383aecbc500d21fa7c /lib/builtins
parentadcf176ce5468872bddbfe2647568612cfd541b8 (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@266388 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins')
-rw-r--r--lib/builtins/emutls.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/builtins/emutls.c b/lib/builtins/emutls.c
index 8d9d64f56..eccbf5336 100644
--- a/lib/builtins/emutls.c
+++ b/lib/builtins/emutls.c
@@ -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*));