]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
VG_(malloc/calloc/strdup) never return NULL (and never will).
authorFlorian Krohm <florian@eich-krohm.de>
Fri, 12 Sep 2014 22:24:51 +0000 (22:24 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Fri, 12 Sep 2014 22:24:51 +0000 (22:24 +0000)
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

20 files changed:
callgrind/bb.c
callgrind/bbcc.c
callgrind/context.c
callgrind/dump.c
callgrind/jumps.c
coregrind/m_aspacehl.c
coregrind/m_commandline.c
coregrind/m_coredump/coredump-elf.c
coregrind/m_initimg/initimg-darwin.c
coregrind/m_initimg/initimg-linux.c
coregrind/m_scheduler/ticket-lock-linux.c
coregrind/m_syswrap/syswrap-darwin.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_ume/elf.c
drd/drd_segment.c
exp-sgcheck/sg_main.c
helgrind/hg_basics.c
helgrind/hg_errors.c
helgrind/hg_main.c
helgrind/libhb_core.c

index c4c9247d037ae196f9d060d600cf992aaafeb64a..0dd1d3358945199e34cbe1f7bab422f444d5f2e6 100644 (file)
@@ -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;
  
index 6682706ee6d9e43e42401469b72732a110227c64..a354b0b3fa36f93cb344ac413161fcdbe149a7f3 100644 (file)
@@ -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;
  
index 853a4d869c570196e3668193370435b7a1412110..92b85276e77a1b5bfc35d0a1ef2179bff964e638 100644 (file)
@@ -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;
 
index f52b840c85ea9d468c0d3d96ab9e2342741e6657..5297d01ebe7fb885aefea5583234ec805da76f9d 100644 (file)
@@ -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.
index c0652f1fabc1b09cbd9e8ae693eeb0ed6e650c2e..ae787b2faf5ba71b2e6c40d77d2ba03f5cc33989 100644 (file)
@@ -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;
  
index b5e296b87139f9a0a8ac8072dca6fb322e4d667f..36fb49d1d115522c7f7fa841314ba2e809ef6efd 100644 (file)
@@ -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;
 }
index 6ff5379818ff782647c63c67de9e019b9a2c3bd2..85e91b419ea46ac7e29ad9ea4d31c688f1ba6cec 100644 (file)
@@ -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);
index 9be2c5374c583c6d5e7ad9f72480aceaf52a62c7..6f2b12c1c2996fad25e13489eba2711a466b210c 100644 (file)
@@ -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;
index 42ef4091aab99a8a553019bc998537c628097dee..21d5bae8483e889c459a35211ad629809d28c7ae 100644 (file)
@@ -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_<tool>_<platform>.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);
 
index a8e7d277674adbc958d13878d56ba493746f2acf..238ab5779ceefaec2932011a4db0b27e595a7d34 100644 (file)
@@ -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_<tool>_<platform>.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);
 
index f80df6d19e4899f556f2cf980a78ef7dd528cbed..bfc8fac0d8aef8153ccc40ba297a70441f4de862 100644 (file)
@@ -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;
index dc48fbad6aa9cdf4bf6359c177e7bd21e9fab187..4bb88b37224ff7e82ea9ded415d5e3c8424e45b6 100644 (file)
@@ -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;
index f3e522efd5c78c884795fd14e2164f614b935bde..44564aea457d96ff3ecd5cd5b374a543b2684a3d 100644 (file)
@@ -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;
index 4615da36edd009edb2e112f4de98ce818c54a256..e15839840f19281e3c4b49bb9d8d2bda6a8cb6dd 100644 (file)
@@ -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';
 
index 32888c27aab48aab4c458ef374d5a05ad6ba5e2f..a625f474321beef466c4e45e5a32d291d0ecd74a 100644 (file)
@@ -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;
index 92b1f675e5d366955405ee43b48b7bb58cdb8811..c9037b046262bb91bf3708e09178382a2638c992 100644 (file)
@@ -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;
 }
 
index 742c5236d724e50d7d3c9d9f4bbbdd74323750a5..984a036746f7b0244b9ac6c90638ba3d70d46b2c 100644 (file)
@@ -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;
 }
index 85c973cfc985725a15274f934ff4bb0dd5a3f578..21ed9c1bc201a6673e1493783fc181d629911663 100644 (file)
@@ -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;
index ef3104140469e01321f6c55867b2fdba561d5a49..9691e0cf5c22f618a8a42cd2f4ca4a2cf31d5483 100644 (file)
@@ -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;
index 5946debb8b74416637bb73eb796b7d2ce933602e..8101f2ae92986f28fcef211a7050534a8d72bc75 100644 (file)
@@ -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;