diff options
author | Jakub Jelinek <jakub@redhat.com> | 2009-06-01 20:03:26 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2009-06-01 20:03:26 +0200 |
commit | df0026a75e538e8bd59d6ed8c91e2e4fdb60d0db (patch) | |
tree | 57674f98cb29f239753d7c9e50143a96835914cf /gcc/emutls.c | |
parent | 6c0d70212d6db24e0223638c5ab5256d7191659b (diff) | |
download | gcc-df0026a75e538e8bd59d6ed8c91e2e4fdb60d0db.tar.gz |
re PR other/40024 (trunk/gcc-4.3/gcc: * emutls.c (emutls_destroy): Don' t fall out of the array bound.)
PR other/40024
* emutls.c (__emutls_get_address): Change arr->size to mean number
of allocated arr->data entries instead of # of slots + 1.
From-SVN: r148061
Diffstat (limited to 'gcc/emutls.c')
-rw-r--r-- | gcc/emutls.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gcc/emutls.c b/gcc/emutls.c index a9c7cf6954c..b7ee3bdfa7c 100644 --- a/gcc/emutls.c +++ b/gcc/emutls.c @@ -155,23 +155,23 @@ __emutls_get_address (struct __emutls_object *obj) if (__builtin_expect (arr == NULL, 0)) { pointer size = offset + 32; - arr = calloc (size, sizeof (void *)); + arr = calloc (size + 1, sizeof (void *)); if (arr == NULL) abort (); arr->size = size; __gthread_setspecific (emutls_key, (void *) arr); } - else if (__builtin_expect (offset >= arr->size, 0)) + else if (__builtin_expect (offset > arr->size, 0)) { pointer orig_size = arr->size; pointer size = orig_size * 2; - if (offset >= size) + if (offset > size) size = offset + 32; - arr = realloc (arr, size * sizeof (void *)); + arr = realloc (arr, (size + 1) * sizeof (void *)); if (arr == NULL) abort (); arr->size = size; - memset (arr->data + orig_size - 1, 0, + memset (arr->data + orig_size, 0, (size - orig_size) * sizeof (void *)); __gthread_setspecific (emutls_key, (void *) arr); } |