]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a bunch of asserts to check the results of calls to system malloc().
authorNicholas Nethercote <n.nethercote@gmail.com>
Sat, 17 Jul 2004 16:40:50 +0000 (16:40 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Sat, 17 Jul 2004 16:40:50 +0000 (16:40 +0000)
Assertions are arguably not the right thing here, but the practice is
widespread and we're not planning on making asserts optional, and it's a lot
better than no checking.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2499

coregrind/ume.c
coregrind/vg_main.c

index 4cfa8eb54ca074e4ca552c7cbd111b7d23fd4813..e85073da000434cc57e450ebac0ec67480075ab1 100644 (file)
@@ -244,6 +244,7 @@ struct elfinfo *readelf(int fd, const char *filename)
    struct elfinfo *e = malloc(sizeof(*e));
    int phsz;
 
+   assert(e);
    e->fd = fd;
 
    if (pread(fd, &e->e, sizeof(e->e), 0) != sizeof(e->e)) {
@@ -282,6 +283,7 @@ struct elfinfo *readelf(int fd, const char *filename)
 
    phsz = sizeof(ESZ(Phdr)) * e->e.e_phnum;
    e->p = malloc(phsz);
+   assert(e->p);
 
    if (pread(fd, e->p, phsz, e->e.e_phoff) != phsz) {
       fprintf(stderr, "can't read phdr: %s\n", strerror(errno));
@@ -422,6 +424,7 @@ static int load_ELF(char *hdr, int len, int fd, const char *name, struct exeinfo
         int intfd;
         int baseaddr_set;
 
+         assert(buf);
         pread(fd, buf, ph->p_filesz, ph->p_offset);
         buf[ph->p_filesz] = '\0';
 
index 53afa33a58d4e61b2b2dce68dfcf42e8f440d95b..e2a15e4836b7be97b96487e1b1344e2274be6a0f 100644 (file)
@@ -653,6 +653,7 @@ static void augment_command_line(Int* vg_argc_inout, char*** vg_argv_inout)
       from    = vg_argv;
       vg_argv = malloc( (vg_argc + env_arg_count + f1_arg_count 
                           + f2_arg_count + 2) * sizeof(char **));
+      vg_assert(vg_argv);
       to      = vg_argv;
 
       /* copy argv[0] */
@@ -711,6 +712,7 @@ static void get_command_line( int argc, char** argv,
            vg_argc++;
 
       vg_argv = malloc(sizeof(char **) * (vg_argc + 1));
+      vg_assert(vg_argv);
 
       cpp = vg_argv;
 
@@ -842,6 +844,7 @@ static char **fix_environment(char **origenv, const char *preload)
       library */
    inject_path_len = sizeof(inject_so) + vgliblen + preloadlen + 16;
    inject_path = malloc(inject_path_len);
+   vg_assert(inject_path);
 
    if (preload)
       snprintf(inject_path, inject_path_len, "%s/%s:%s", 
@@ -857,6 +860,7 @@ static char **fix_environment(char **origenv, const char *preload)
 
    /* Allocate a new space */
    ret = malloc(sizeof(char *) * (envc+3+1)); /* 3 new entries + NULL */
+   vg_assert(ret);
 
    /* copy it over */
    for (cpp = ret; *origenv; )
@@ -875,6 +879,7 @@ static char **fix_environment(char **origenv, const char *preload)
          if (!scan_colsep(*cpp + ld_library_path_len, contains)) {
            int len = strlen(*cpp) + vgliblen*2 + 16;
            char *cp = malloc(len);
+            vg_assert(cp);
 
            snprintf(cp, len, "%s%s:%s",
                     ld_library_path, VG_(libdir),
@@ -887,6 +892,7 @@ static char **fix_environment(char **origenv, const char *preload)
       } else if (memcmp(*cpp, ld_preload, ld_preload_len) == 0) {
         int len = strlen(*cpp) + inject_path_len;
         char *cp = malloc(len);
+         vg_assert(cp);
 
         snprintf(cp, len, "%s%s:%s",
                  ld_preload, inject_path, (*cpp)+ld_preload_len);
@@ -904,6 +910,7 @@ static char **fix_environment(char **origenv, const char *preload)
    if (!ld_library_path_done) {
       int len = ld_library_path_len + vgliblen*2 + 16;
       char *cp = malloc(len);
+      vg_assert(cp);
 
       snprintf(cp, len, "%s%s", ld_library_path, VG_(libdir));
 
@@ -913,6 +920,7 @@ static char **fix_environment(char **origenv, const char *preload)
    if (!ld_preload_done) {
       int len = ld_preload_len + inject_path_len;
       char *cp = malloc(len);
+      vg_assert(cp);
       
       snprintf(cp, len, "%s%s",
               ld_preload, inject_path);