From: Florian Krohm Date: Fri, 12 Sep 2014 22:24:51 +0000 (+0000) Subject: VG_(malloc/calloc/strdup) never return NULL (and never will). X-Git-Tag: svn/VALGRIND_3_11_0~1004 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33f32780a533ac1daa420a51eb8fab64459f9416;p=thirdparty%2Fvalgrind.git VG_(malloc/calloc/strdup) never return NULL (and never will). So it's pointless to test or assert their return values. Remove code doing so. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14528 --- diff --git a/callgrind/bb.c b/callgrind/bb.c index c4c9247d03..0dd1d33589 100644 --- a/callgrind/bb.c +++ b/callgrind/bb.c @@ -74,8 +74,6 @@ void resize_bb_table(void) new_table = (BB**) CLG_MALLOC("cl.bb.rbt.1", new_size * sizeof(BB*)); - if (!new_table) return; - for (i = 0; i < new_size; i++) new_table[i] = NULL; diff --git a/callgrind/bbcc.c b/callgrind/bbcc.c index 6682706ee6..a354b0b3fa 100644 --- a/callgrind/bbcc.c +++ b/callgrind/bbcc.c @@ -201,8 +201,6 @@ static void resize_bbcc_hash(void) new_table = (BBCC**) CLG_MALLOC("cl.bbcc.rbh.1", new_size * sizeof(BBCC*)); - if (!new_table) return; - for (i = 0; i < new_size; i++) new_table[i] = NULL; diff --git a/callgrind/context.c b/callgrind/context.c index 853a4d869c..92b85276e7 100644 --- a/callgrind/context.c +++ b/callgrind/context.c @@ -93,8 +93,6 @@ static void resize_cxt_table(void) new_table = (Context**) CLG_MALLOC("cl.context.rct.1", new_size * sizeof(Context*)); - if (!new_table) return; - for (i = 0; i < new_size; i++) new_table[i] = NULL; diff --git a/callgrind/dump.c b/callgrind/dump.c index f52b840c85..5297d01ebe 100644 --- a/callgrind/dump.c +++ b/callgrind/dump.c @@ -1682,7 +1682,6 @@ void CLG_(init_dumps)() /* allocate space big enough for final filenames */ filename = (HChar*) CLG_MALLOC("cl.dump.init_dumps.2", VG_(strlen)(out_file)+32); - CLG_ASSERT(filename != 0); /* Make sure the output base file can be written. * This is used for the dump at program termination. diff --git a/callgrind/jumps.c b/callgrind/jumps.c index c0652f1fab..ae787b2faf 100644 --- a/callgrind/jumps.c +++ b/callgrind/jumps.c @@ -91,8 +91,6 @@ static void resize_jcc_table(void) new_table = (jCC**) CLG_MALLOC("cl.jumps.rjt.1", new_size * sizeof(jCC*)); - if (!new_table) return; - for (i = 0; i < new_size; i++) new_table[i] = NULL; diff --git a/coregrind/m_aspacehl.c b/coregrind/m_aspacehl.c index b5e296b871..36fb49d1d1 100644 --- a/coregrind/m_aspacehl.c +++ b/coregrind/m_aspacehl.c @@ -46,8 +46,6 @@ Addr* VG_(get_segment_starts) ( /*OUT*/Int* n_acquired ) n_starts = 1; while (True) { starts = VG_(malloc)( "main.gss.1", n_starts * sizeof(Addr) ); - if (starts == NULL) - break; r = VG_(am_get_segment_starts)( starts, n_starts ); if (r >= 0) break; @@ -55,11 +53,6 @@ Addr* VG_(get_segment_starts) ( /*OUT*/Int* n_acquired ) n_starts *= 2; } - if (starts == NULL) { - *n_acquired = 0; - return NULL; - } - *n_acquired = r; return starts; } diff --git a/coregrind/m_commandline.c b/coregrind/m_commandline.c index 6ff5379818..85e91b419e 100644 --- a/coregrind/m_commandline.c +++ b/coregrind/m_commandline.c @@ -71,7 +71,6 @@ static HChar* read_dot_valgrindrc ( const HChar* dir ) && (!(stat_buf.mode & VKI_S_IWOTH))) { if ( stat_buf.size > 0 ) { f_clo = VG_(malloc)("commandline.rdv.1", stat_buf.size+1); - vg_assert(f_clo); n = VG_(read)(sr_Res(fd), f_clo, stat_buf.size); if (n == -1) n = 0; vg_assert(n >= 0 && n <= stat_buf.size+1); diff --git a/coregrind/m_coredump/coredump-elf.c b/coregrind/m_coredump/coredump-elf.c index 9be2c5374c..6f2b12c1c2 100644 --- a/coregrind/m_coredump/coredump-elf.c +++ b/coregrind/m_coredump/coredump-elf.c @@ -603,7 +603,6 @@ void make_elf_coredump(ThreadId tid, const vki_siginfo_t *si, ULong max_size) buf = VG_(malloc)( "coredump-elf.mec.1", VG_(strlen)(coreext) + VG_(strlen)(basename) + 100/*for the two %ds. */ ); - vg_assert(buf); for(;;) { Int oflags = VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC; diff --git a/coregrind/m_initimg/initimg-darwin.c b/coregrind/m_initimg/initimg-darwin.c index 42ef4091aa..21d5bae848 100644 --- a/coregrind/m_initimg/initimg-darwin.c +++ b/coregrind/m_initimg/initimg-darwin.c @@ -143,12 +143,10 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) + sizeof(VG_PLATFORM) + 16; Int preload_string_len = preload_core_path_len + preload_tool_path_len; HChar* preload_string = VG_(malloc)("initimg-darwin.sce.1", preload_string_len); - vg_assert(preload_string); /* Determine if there's a vgpreload__.so file, and setup preload_string. */ preload_tool_path = VG_(malloc)("initimg-darwin.sce.2", preload_tool_path_len); - vg_assert(preload_tool_path); VG_(snprintf)(preload_tool_path, preload_tool_path_len, "%s/vgpreload_%s-%s.so", VG_(libdir), toolname, VG_PLATFORM); if (VG_(access)(preload_tool_path, True/*r*/, False/*w*/, False/*x*/) == 0) { @@ -171,7 +169,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) /* Allocate a new space */ ret = VG_(malloc) ("initimg-darwin.sce.3", sizeof(HChar *) * (envc+2+1)); /* 2 new entries + NULL */ - vg_assert(ret); /* copy it over */ for (cpp = ret; *origenv; ) @@ -185,7 +182,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) if (VG_(memcmp)(*cpp, ld_preload, ld_preload_len) == 0) { Int len = VG_(strlen)(*cpp) + preload_string_len; HChar *cp = VG_(malloc)("initimg-darwin.sce.4", len); - vg_assert(cp); VG_(snprintf)(cp, len, "%s%s:%s", ld_preload, preload_string, (*cpp)+ld_preload_len); @@ -197,7 +193,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) if (VG_(memcmp)(*cpp, dyld_cache, dyld_cache_len) == 0) { Int len = dyld_cache_len + VG_(strlen)(dyld_cache_value) + 1; HChar *cp = VG_(malloc)("initimg-darwin.sce.4.2", len); - vg_assert(cp); VG_(snprintf)(cp, len, "%s%s", dyld_cache, dyld_cache_value); @@ -211,7 +206,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) if (!ld_preload_done) { Int len = ld_preload_len + preload_string_len; HChar *cp = VG_(malloc) ("initimg-darwin.sce.5", len); - vg_assert(cp); VG_(snprintf)(cp, len, "%s%s", ld_preload, preload_string); @@ -220,7 +214,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) if (!dyld_cache_done) { Int len = dyld_cache_len + VG_(strlen)(dyld_cache_value) + 1; HChar *cp = VG_(malloc) ("initimg-darwin.sce.5.2", len); - vg_assert(cp); VG_(snprintf)(cp, len, "%s%s", dyld_cache, dyld_cache_value); diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c index a8e7d27767..238ab5779c 100644 --- a/coregrind/m_initimg/initimg-linux.c +++ b/coregrind/m_initimg/initimg-linux.c @@ -126,6 +126,9 @@ static void load_client ( /*OUT*/ExeInfo* info, */ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) { + vg_assert(origenv); + vg_assert(toolname); + const HChar* preload_core = "vgpreload_core"; const HChar* ld_preload = "LD_PRELOAD="; const HChar* v_launcher = VALGRIND_LAUNCHER "="; @@ -151,14 +154,9 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) Int preload_string_len = preload_core_path_len + preload_tool_path_len; HChar* preload_string = VG_(malloc)("initimg-linux.sce.1", preload_string_len); - vg_assert(origenv); - vg_assert(toolname); - vg_assert(preload_string); - /* Determine if there's a vgpreload__.so file, and setup preload_string. */ preload_tool_path = VG_(malloc)("initimg-linux.sce.2", preload_tool_path_len); - vg_assert(preload_tool_path); VG_(snprintf)(preload_tool_path, preload_tool_path_len, "%s/vgpreload_%s-%s.so", VG_(libdir), toolname, VG_PLATFORM); if (VG_(access)(preload_tool_path, True/*r*/, False/*w*/, False/*x*/) == 0) { @@ -184,7 +182,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) /* Allocate a new space */ ret = VG_(malloc) ("initimg-linux.sce.3", sizeof(HChar *) * (envc+1+1)); /* 1 new entry + NULL */ - vg_assert(ret); /* copy it over */ for (cpp = ret; *origenv; ) { @@ -200,7 +197,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) if (VG_(memcmp)(*cpp, ld_preload, ld_preload_len) == 0) { Int len = VG_(strlen)(*cpp) + preload_string_len; HChar *cp = VG_(malloc)("initimg-linux.sce.4", len); - vg_assert(cp); VG_(snprintf)(cp, len, "%s%s:%s", ld_preload, preload_string, (*cpp)+ld_preload_len); @@ -216,7 +212,6 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) if (!ld_preload_done) { Int len = ld_preload_len + preload_string_len; HChar *cp = VG_(malloc) ("initimg-linux.sce.5", len); - vg_assert(cp); VG_(snprintf)(cp, len, "%s%s", ld_preload, preload_string); diff --git a/coregrind/m_scheduler/ticket-lock-linux.c b/coregrind/m_scheduler/ticket-lock-linux.c index f80df6d19e..bfc8fac0d8 100644 --- a/coregrind/m_scheduler/ticket-lock-linux.c +++ b/coregrind/m_scheduler/ticket-lock-linux.c @@ -78,15 +78,15 @@ static struct sched_lock *create_sched_lock(void) struct sched_lock *p; p = VG_(malloc)("sched_lock", sizeof(*p)); - if (p) { - // The futex syscall requires that a futex takes four bytes. - vg_assert(sizeof(p->futex[0]) == 4); - - p->head = 0; - p->tail = 0; - VG_(memset)((void*)p->futex, 0, sizeof(p->futex)); - p->owner = 0; - } + + // The futex syscall requires that a futex takes four bytes. + vg_assert(sizeof(p->futex[0]) == 4); + + p->head = 0; + p->tail = 0; + VG_(memset)((void*)p->futex, 0, sizeof(p->futex)); + p->owner = 0; + INNER_REQUEST(ANNOTATE_RWLOCK_CREATE(p)); INNER_REQUEST(ANNOTATE_BENIGN_RACE_SIZED(&p->futex, sizeof(p->futex), "")); return p; diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index dc48fbad6a..4bb88b3722 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -3043,7 +3043,6 @@ PRE(posix_spawn) // allocate argv = VG_(malloc)( "di.syswrap.pre_sys_execve.1", (tot_args+1) * sizeof(HChar*) ); - vg_assert(argv); // copy j = 0; argv[j++] = launcher_basename; diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index f3e522efd5..44564aea45 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -2856,7 +2856,6 @@ PRE(sys_execve) // allocate argv = VG_(malloc)( "di.syswrap.pre_sys_execve.1", (tot_args+1) * sizeof(HChar*) ); - if (argv == 0) goto hosed; // copy j = 0; argv[j++] = launcher_basename; diff --git a/coregrind/m_ume/elf.c b/coregrind/m_ume/elf.c index 4615da36ed..e15839840f 100644 --- a/coregrind/m_ume/elf.c +++ b/coregrind/m_ume/elf.c @@ -95,7 +95,6 @@ struct elfinfo *readelf(Int fd, const HChar *filename) struct elfinfo *e = VG_(malloc)("ume.re.1", sizeof(*e)); Int phsz; - vg_assert(e); e->fd = fd; sres = VG_(pread)(fd, &e->e, sizeof(e->e), 0); @@ -136,7 +135,6 @@ struct elfinfo *readelf(Int fd, const HChar *filename) phsz = sizeof(ESZ(Phdr)) * e->e.e_phnum; e->p = VG_(malloc)("ume.re.2", phsz); - vg_assert(e->p); sres = VG_(pread)(fd, e->p, phsz, e->e.e_phoff); if (sr_isError(sres) || sr_Res(sres) != phsz) { @@ -372,7 +370,6 @@ Int VG_(load_ELF)(Int fd, const HChar* name, /*MOD*/ExeInfo* info) Int intfd; Int baseaddr_set; - vg_assert(buf); VG_(pread)(fd, buf, ph->p_filesz, ph->p_offset); buf[ph->p_filesz] = '\0'; diff --git a/drd/drd_segment.c b/drd/drd_segment.c index 32888c27aa..a625f47432 100644 --- a/drd/drd_segment.c +++ b/drd/drd_segment.c @@ -124,7 +124,6 @@ Segment* DRD_(sg_new)(const DrdThreadId creator, const DrdThreadId created) s_max_segments_alive_count = s_segments_alive_count; sg = VG_(malloc)("drd.segment.sn.1", sizeof(*sg)); - tl_assert(sg); sg_init(sg, creator, created); if (DRD_(g_sg_list)) { DRD_(g_sg_list)->g_prev = sg; diff --git a/exp-sgcheck/sg_main.c b/exp-sgcheck/sg_main.c index 92b1f675e5..c9037b0462 100644 --- a/exp-sgcheck/sg_main.c +++ b/exp-sgcheck/sg_main.c @@ -73,7 +73,6 @@ static void* sg_malloc ( const HChar* cc, SizeT n ) { void* p; tl_assert(n > 0); p = VG_(malloc)( cc, n ); - tl_assert(p); return p; } diff --git a/helgrind/hg_basics.c b/helgrind/hg_basics.c index 742c5236d7..984a036746 100644 --- a/helgrind/hg_basics.c +++ b/helgrind/hg_basics.c @@ -47,7 +47,6 @@ void* HG_(zalloc) ( const HChar* cc, SizeT n ) void* p; tl_assert(n > 0); p = VG_(malloc)( cc, n ); - tl_assert(p); VG_(memset)(p, 0, n); return p; } diff --git a/helgrind/hg_errors.c b/helgrind/hg_errors.c index 85c973cfc9..21ed9c1bc2 100644 --- a/helgrind/hg_errors.c +++ b/helgrind/hg_errors.c @@ -85,7 +85,6 @@ static HChar* string_table_strdup ( const HChar* str ) { return copy; } else { copy = HG_(strdup)("hg.sts.2", str); - tl_assert(copy); VG_(addToFM)( string_table, (UWord)copy, (UWord)copy ); return copy; } @@ -202,7 +201,6 @@ Lock** enumerate_WordSet_into_LockP_vector( WordSetU* univ_lsets, UWord nLocks = HG_(cardinalityWS)(univ_lsets, lockset); Lock** lockPs = HG_(zalloc)( "hg.eWSiLPa", (nLocks+1) * sizeof(Lock*) ); - tl_assert(lockPs); tl_assert(lockPs[nLocks] == NULL); /* pre-NULL terminated */ UWord* lockNs = NULL; UWord nLockNs = 0; diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index ef31041404..9691e0cf5c 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -595,7 +595,6 @@ static void initialise_data_structures ( Thr* hbthr_root ) tl_assert(map_threads == NULL); map_threads = HG_(zalloc)( "hg.ids.1", VG_N_THREADS * sizeof(Thread*) ); - tl_assert(map_threads != NULL); tl_assert(sizeof(Addr) == sizeof(UWord)); tl_assert(map_locks == NULL); @@ -2853,7 +2852,6 @@ typedef static Bar* new_Bar ( void ) { Bar* bar = HG_(zalloc)( "hg.nB.1 (new_Bar)", sizeof(Bar) ); - tl_assert(bar); /* all fields are zero */ tl_assert(bar->initted == False); return bar; diff --git a/helgrind/libhb_core.c b/helgrind/libhb_core.c index 5946debb8b..8101f2ae92 100644 --- a/helgrind/libhb_core.c +++ b/helgrind/libhb_core.c @@ -882,7 +882,6 @@ void alloc_F_for_writing ( /*MOD*/SecMap* sm, /*OUT*/Word* fixp ) { new_size = sm->linesF_size==0 ? 1 : 2 * sm->linesF_size; nyu = HG_(zalloc)( "libhb.aFfw.1 (LineF storage)", new_size * sizeof(LineF) ); - tl_assert(nyu); stats__secmap_linesF_allocd += (new_size - sm->linesF_size); stats__secmap_linesF_bytes += (new_size - sm->linesF_size) @@ -4411,7 +4410,6 @@ static void event_map_init ( void ) tl_assert(!contextTab); contextTab = HG_(zalloc)( "libhb.event_map_init.2 (context table)", N_RCEC_TAB * sizeof(RCEC*) ); - tl_assert(contextTab); for (i = 0; i < N_RCEC_TAB; i++) contextTab[i] = NULL;