From: DJ Delorie Date: Fri, 15 Jul 2016 22:26:14 +0000 (-0400) Subject: Fix NULL return value handling X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcf17bd0d948d19c84ab72ba0a57688f4533327d;p=thirdparty%2Fglibc.git Fix NULL return value handling Decided that a call that returns NULL should be encoded in the workload but that the simulator should just skip those calls, rather than skip them in the converter. --- diff --git a/malloc/trace2wl.cc b/malloc/trace2wl.cc index aa53fb36768..5fe7b556ec6 100644 --- a/malloc/trace2wl.cc +++ b/malloc/trace2wl.cc @@ -276,14 +276,17 @@ main(int argc, char **argv) case __MTB_TYPE_MALLOC: case __MTB_TYPE_CALLOC: acq_ptr (thread, pa2); - if (pa2->valid) + if (pa2 && pa2->valid) printf ("%d: pointer %p malloc'd again? %d:%s\n", i, pa2->ptr, pa2->reason_idx, pa2->reason); thread->add (r->type == __MTB_TYPE_MALLOC ? C_MALLOC : C_CALLOC); - thread->add_int (pa2->idx); + thread->add_int (pa2 ? pa2->idx : 0); thread->add_int (r->size); - pa2->valid = 1; - pa2->reason = "malloc"; - pa2->reason_idx = i; + if (pa2) + { + pa2->valid = 1; + pa2->reason = "malloc"; + pa2->reason_idx = i; + } break; case __MTB_TYPE_FREE: diff --git a/malloc/trace_run.c b/malloc/trace_run.c index a42e81d80fa..e64b18981a3 100644 --- a/malloc/trace_run.c +++ b/malloc/trace_run.c @@ -242,6 +242,9 @@ thread_common (void *my_data_v) p2 = get_int (&cp); sz = get_int (&cp); dprintf("op %d:%ld %ld = MALLOC %ld\n", (int)me, cp-data, p2, sz); + /* we can't force malloc to return NULL (fail), so just skip it. */ + if (p2 == 0) + break; if (p2 > n_ptrs) myabort(); stime = rdtsc_s(); @@ -271,6 +274,9 @@ thread_common (void *my_data_v) p2 = get_int (&cp); sz = get_int (&cp); dprintf("op %d:%ld %ld = CALLOC %ld\n", (int)me, cp-data, p2, sz); + /* we can't force calloc to return NULL (fail), so just skip it. */ + if (p2 == 0) + break; if (p2 > n_ptrs) myabort(); if (ptrs[p2]) @@ -303,6 +309,16 @@ thread_common (void *my_data_v) if (ptrs[p1]) atomic_rss (-sizes[p1]); free_wipe(p1); + /* we can't force realloc to return NULL (fail), so just skip it. */ + if (p2 == 0) + { + if (p1) + { + free ((void *)ptrs[p1]); + ptrs[p1] = 0; + } + break; + } stime = rdtsc_s(); Q1; #ifdef MDEBUG