Commit df0026a7 by Jakub Jelinek Committed by Jakub Jelinek

re PR other/40024 (trunk/gcc-4.3/gcc: * emutls.c (emutls_destroy): Don' t fall…

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
parent 6c0d7021
2009-06-01 Jakub Jelinek <jakub@redhat.com> 2009-06-01 Jakub Jelinek <jakub@redhat.com>
PR other/40024
* emutls.c (__emutls_get_address): Change arr->size to mean number
of allocated arr->data entries instead of # of slots + 1.
PR middle-end/40316 PR middle-end/40316
* recog.c (peep2_reinit_state): New function. * recog.c (peep2_reinit_state): New function.
(peephole2_init_state): Use it at the end of a basic block and also (peephole2_init_state): Use it at the end of a basic block and also
......
...@@ -155,23 +155,23 @@ __emutls_get_address (struct __emutls_object *obj) ...@@ -155,23 +155,23 @@ __emutls_get_address (struct __emutls_object *obj)
if (__builtin_expect (arr == NULL, 0)) if (__builtin_expect (arr == NULL, 0))
{ {
pointer size = offset + 32; pointer size = offset + 32;
arr = calloc (size, sizeof (void *)); arr = calloc (size + 1, sizeof (void *));
if (arr == NULL) if (arr == NULL)
abort (); abort ();
arr->size = size; arr->size = size;
__gthread_setspecific (emutls_key, (void *) arr); __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 orig_size = arr->size;
pointer size = orig_size * 2; pointer size = orig_size * 2;
if (offset >= size) if (offset > size)
size = offset + 32; size = offset + 32;
arr = realloc (arr, size * sizeof (void *)); arr = realloc (arr, (size + 1) * sizeof (void *));
if (arr == NULL) if (arr == NULL)
abort (); abort ();
arr->size = size; arr->size = size;
memset (arr->data + orig_size - 1, 0, memset (arr->data + orig_size, 0,
(size - orig_size) * sizeof (void *)); (size - orig_size) * sizeof (void *));
__gthread_setspecific (emutls_key, (void *) arr); __gthread_setspecific (emutls_key, (void *) arr);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment