Fix calls to {m,c,re}alloc so that they use x{m,c,re}alloc instead of
authorkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>
Wed, 13 Sep 2000 02:46:14 +0000 (02:46 +0000)
committerkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>
Wed, 13 Sep 2000 02:46:14 +0000 (02:46 +0000)
segfaulting or handling errors the same way themselves.

git-svn-id: svn://busybox.net/trunk/busybox@1039 69ca8d6d-28ef-0310-b511-8ec308f3f277

25 files changed:
ar.c
archival/ar.c
cmdedit.c
console-tools/loadfont.c
console-tools/loadkmap.c
coreutils/ln.c
coreutils/sort.c
coreutils/tail.c
coreutils/test.c
editors/sed.c
findutils/which.c
ln.c
loadfont.c
loadkmap.c
mount.c
procps/ps.c
ps.c
sed.c
shell/cmdedit.c
sort.c
tail.c
test.c
util-linux/mount.c
utility.c
which.c

diff --git a/ar.c b/ar.c
index d82763d..241c1fa 100644 (file)
--- a/ar.c
+++ b/ar.c
@@ -246,7 +246,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
        headerL_t *list;
        off_t initialOffset;
 
-        list = (headerL_t *) malloc(sizeof(headerL_t));
+       list = (headerL_t *) xmalloc(sizeof(headerL_t));
        initialOffset=lseek(srcFd, 0, SEEK_CUR);
        if (checkArMagic(srcFd)==TRUE) 
                ar=TRUE;
@@ -258,7 +258,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
         if (tar==TRUE) {
                 while(readTarHeader(srcFd, list)==TRUE) {
                        off_t tarOffset;
-                        list->next = (headerL_t *) malloc(sizeof(headerL_t));
+                        list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
                         *list->next = *head;
                         *head = *list;
 
@@ -282,7 +282,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
                                if (readArEntry(srcFd, list) == FALSE)
                                        return(head);
                        }
-                       list->next = (headerL_t *) malloc(sizeof(headerL_t));
+                       list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
                        *list->next = *head;
                        *head = *list;
                        /* recursive check for sub-archives */
@@ -349,9 +349,9 @@ extern int ar_main(int argc, char **argv)
                 return (FALSE);
         }
        optind++;       
-       entry = (headerL_t *) malloc(sizeof(headerL_t));
-       header = (headerL_t *) malloc(sizeof(headerL_t));
-       extractList = (headerL_t *) malloc(sizeof(headerL_t));  
+       entry = (headerL_t *) xmalloc(sizeof(headerL_t));
+       header = (headerL_t *) xmalloc(sizeof(headerL_t));
+       extractList = (headerL_t *) xmalloc(sizeof(headerL_t)); 
 
        header = getHeaders(srcFd, header, funct);
        /* find files to extract or display */
@@ -359,7 +359,7 @@ extern int ar_main(int argc, char **argv)
                /* only handle specified files */
                while(optind < argc) { 
                        if ( (entry = findEntry(header, argv[optind])) != NULL) {
-                               entry->next = (headerL_t *) malloc(sizeof(headerL_t));
+                               entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
                                *entry->next = *extractList;
                                *extractList = *entry;
                        }
index d82763d..241c1fa 100644 (file)
@@ -246,7 +246,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
        headerL_t *list;
        off_t initialOffset;
 
-        list = (headerL_t *) malloc(sizeof(headerL_t));
+       list = (headerL_t *) xmalloc(sizeof(headerL_t));
        initialOffset=lseek(srcFd, 0, SEEK_CUR);
        if (checkArMagic(srcFd)==TRUE) 
                ar=TRUE;
@@ -258,7 +258,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
         if (tar==TRUE) {
                 while(readTarHeader(srcFd, list)==TRUE) {
                        off_t tarOffset;
-                        list->next = (headerL_t *) malloc(sizeof(headerL_t));
+                        list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
                         *list->next = *head;
                         *head = *list;
 
@@ -282,7 +282,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
                                if (readArEntry(srcFd, list) == FALSE)
                                        return(head);
                        }
-                       list->next = (headerL_t *) malloc(sizeof(headerL_t));
+                       list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
                        *list->next = *head;
                        *head = *list;
                        /* recursive check for sub-archives */
@@ -349,9 +349,9 @@ extern int ar_main(int argc, char **argv)
                 return (FALSE);
         }
        optind++;       
-       entry = (headerL_t *) malloc(sizeof(headerL_t));
-       header = (headerL_t *) malloc(sizeof(headerL_t));
-       extractList = (headerL_t *) malloc(sizeof(headerL_t));  
+       entry = (headerL_t *) xmalloc(sizeof(headerL_t));
+       header = (headerL_t *) xmalloc(sizeof(headerL_t));
+       extractList = (headerL_t *) xmalloc(sizeof(headerL_t)); 
 
        header = getHeaders(srcFd, header, funct);
        /* find files to extract or display */
@@ -359,7 +359,7 @@ extern int ar_main(int argc, char **argv)
                /* only handle specified files */
                while(optind < argc) { 
                        if ( (entry = findEntry(header, argv[optind])) != NULL) {
-                               entry->next = (headerL_t *) malloc(sizeof(headerL_t));
+                               entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
                                *entry->next = *extractList;
                                *extractList = *entry;
                        }
index 042064f..04abc93 100644 (file)
--- a/cmdedit.c
+++ b/cmdedit.c
@@ -246,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
 char** exe_n_cwd_tab_completion(char* command, int *num_matches)
 {
        char *dirName;
-       char **matches = (char **) NULL;
+       char **matches;
        DIR *dir;
        struct dirent *next;
                        
-       matches = malloc( sizeof(char*)*50);
+       matches = xmalloc( sizeof(char*)*50);
 
        /* Stick a wildcard onto the command, for later use */
        strcat( command, "*");
@@ -273,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
                /* See if this matches */
                if (check_wildcard_match(next->d_name, command) == TRUE) {
                        /* Cool, found a match.  Add it to the list */
-                       matches[*num_matches] = malloc(strlen(next->d_name)+1);
+                       matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
                        strcpy( matches[*num_matches], next->d_name);
                        ++*num_matches;
                        //matches = realloc( matches, sizeof(char*)*(*num_matches));
@@ -302,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
 
                /* Make a local copy of the string -- up 
                 * to the position of the cursor */
-               matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
+               matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
                strncpy(matchBuf, command, cursor);
                tmp=matchBuf;
 
@@ -670,8 +670,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
 
                if (!h) {
                        /* No previous history -- this memory is never freed */
-                       h = his_front = malloc(sizeof(struct history));
-                       h->n = malloc(sizeof(struct history));
+                       h = his_front = xmalloc(sizeof(struct history));
+                       h->n = xmalloc(sizeof(struct history));
 
                        h->p = NULL;
                        h->s = strdup(command);
@@ -682,7 +682,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
                        history_counter++;
                } else {
                        /* Add a new history command -- this memory is never freed */
-                       h->n = malloc(sizeof(struct history));
+                       h->n = xmalloc(sizeof(struct history));
 
                        h->n->p = h;
                        h->n->n = NULL;
index 927c2ba..e93ca31 100644 (file)
@@ -102,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
        u_short unicode;
 
        maxct = tailsz;                         /* more than enough */
-       up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
+       up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
 
-       if (!up) {
-               errorMsg("Out of memory?\n");
-               exit(1);
-       }
        for (glyph = 0; glyph < fontsize; glyph++) {
                while (tailsz >= 2) {
                        unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
index 488585f..2321a1e 100644 (file)
@@ -67,11 +67,7 @@ int loadkmap_main(int argc, char **argv)
                exit(FALSE);
        }
 
-       ibuff = (u_short *) malloc(ibuffsz);
-       if (!ibuff) {
-               errorMsg("Out of memory.\n");
-               exit(FALSE);
-       }
+       ibuff = (u_short *) xmalloc(ibuffsz);
 
        for (i = 0; i < MAX_NR_KEYMAPS; i++) {
                if (flags[i] == 1) {
index 8b8fa1c..d5f44ea 100644 (file)
@@ -90,7 +90,7 @@ extern int ln_main(int argc, char **argv)
 
                if (linkIntoDirFlag == TRUE) {
                        char *baseName = get_last_path_component(*argv);
-                       linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
+                       linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
                        strcpy(linkName, dirName);
                        if(dirName[strlen(dirName)-1] != '/')
                                strcat(linkName, "/");
index 6af5c4d..a74f96a 100644 (file)
@@ -64,7 +64,7 @@ static const int max = 1024;
 static Line *line_alloc()
 {
        Line *self;
-       self = malloc(1 * sizeof(Line));
+       self = xmalloc(1 * sizeof(Line));
        return self;
 }
 
@@ -76,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
 
        if ((cstring = get_line_from_file(src))) {
                self = line_alloc();
-               if (self == NULL) {
-                       return NULL;
-               }
                self->data = cstring;
                self->next = NULL;
                return self;
@@ -173,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
        Line *line;
 
        /* mallocate array of Line*s */
-       self->sorted = (Line **) malloc(self->len * sizeof(Line *));
-       if (self->sorted == NULL) {
-               return NULL;
-       }
+       self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
 
        /* fill array w/ List's contents */
        i = 0;
@@ -294,4 +288,4 @@ int sort_main(int argc, char **argv)
        return(0);
 }
 
-/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */
+/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */
index c940bfe..dcb4f67 100644 (file)
@@ -87,12 +87,12 @@ int tail_stream(int fd)
                        ssize_t f_size=0;
 
                        bs=BUFSIZ;
-                       line=malloc(bs);
+                       line=xmalloc(bs);
                        while(1) {
                                bytes_read=read(fd,line,bs);
                                if(bytes_read<=0)
                                        break;
-                               buffer=realloc(buffer,f_size+bytes_read);
+                               buffer=xrealloc(buffer,f_size+bytes_read);
                                memcpy(&buffer[f_size],line,bytes_read);
                                filelocation=f_size+=bytes_read;
                        }
@@ -150,8 +150,8 @@ int tail_stream(int fd)
 void add_file(char *name)
 {
        ++n_files;
-       files = realloc(files, n_files);
-       files[n_files - 1] = (char *) malloc(strlen(name) + 1);
+       files = xrealloc(files, n_files);
+       files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
        strcpy(files[n_files - 1], name);
 }
 
@@ -268,13 +268,13 @@ int tail_main(int argc, char **argv)
                units=-11;
        if(units>0)
                units--;
-       fd=malloc(sizeof(int)*n_files);
+       fd=xmalloc(sizeof(int)*n_files);
        if (n_files == 1)
 #ifndef BB_FEATURE_SIMPLE_TAIL
                if (!verbose)
 #endif
                        show_headers = 0;
-       buffer=malloc(BUFSIZ);
+       buffer=xmalloc(BUFSIZ);
        for (test = 0; test < n_files; test++) {
                if (show_headers)
                        printf("==> %s <==\n", files[test]);
index 6dde718..a2bec44 100644 (file)
@@ -555,9 +555,7 @@ static void
 initialize_group_array ()
 {
        ngroups = getgroups(0, NULL);
-       if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
-               fatalError("Out of space\n");
-
+       group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
        getgroups(ngroups, group_array);
 }
 
index f3c3262..0e0d7f5 100644 (file)
@@ -44,7 +44,6 @@
 */
 
 #include <stdio.h>
-#include <stdlib.h> /* for realloc() */
 #include <unistd.h> /* for getopt() */
 #include <regex.h>
 #include <string.h> /* for strdup() */
@@ -457,7 +456,7 @@ static void add_cmd_str(const char *cmdstr)
                        continue;
                }
                /* grow the array */
-               sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
+               sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
                /* zero new element */
                memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
                /* load command string into new array element, get remainder */
@@ -481,7 +480,7 @@ static void load_cmd_file(char *filename)
                /* if a line ends with '\' it needs the next line appended to it */
                while (line[strlen(line)-2] == '\\' &&
                                (nextline = get_line_from_file(cmdfile)) != NULL) {
-                       line = realloc(line, strlen(line) + strlen(nextline) + 1);
+                       line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
                        strcat(line, nextline);
                        free(nextline);
                }
index b3fd934..07c0e0d 100644 (file)
@@ -40,7 +40,7 @@ extern int which_main(int argc, char **argv)
        if (!path_list)
                path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
 
-       path_parsed = malloc (strlen(path_list) + 1);
+       path_parsed = xmalloc (strlen(path_list) + 1);
        strcpy (path_parsed, path_list);
 
        /* Replace colons with zeros in path_parsed and count them */
diff --git a/ln.c b/ln.c
index 8b8fa1c..d5f44ea 100644 (file)
--- a/ln.c
+++ b/ln.c
@@ -90,7 +90,7 @@ extern int ln_main(int argc, char **argv)
 
                if (linkIntoDirFlag == TRUE) {
                        char *baseName = get_last_path_component(*argv);
-                       linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
+                       linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
                        strcpy(linkName, dirName);
                        if(dirName[strlen(dirName)-1] != '/')
                                strcat(linkName, "/");
index 927c2ba..e93ca31 100644 (file)
@@ -102,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
        u_short unicode;
 
        maxct = tailsz;                         /* more than enough */
-       up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
+       up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
 
-       if (!up) {
-               errorMsg("Out of memory?\n");
-               exit(1);
-       }
        for (glyph = 0; glyph < fontsize; glyph++) {
                while (tailsz >= 2) {
                        unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
index 488585f..2321a1e 100644 (file)
@@ -67,11 +67,7 @@ int loadkmap_main(int argc, char **argv)
                exit(FALSE);
        }
 
-       ibuff = (u_short *) malloc(ibuffsz);
-       if (!ibuff) {
-               errorMsg("Out of memory.\n");
-               exit(FALSE);
-       }
+       ibuff = (u_short *) xmalloc(ibuffsz);
 
        for (i = 0; i < MAX_NR_KEYMAPS; i++) {
                if (flags[i] == 1) {
diff --git a/mount.c b/mount.c
index b4f5746..15ab5c9 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -273,7 +273,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
                numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
                if (numfilesystems<0)
                        fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
-               fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
+               fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
 
                /* Grab the list of available filesystems */
                status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
@@ -343,7 +343,7 @@ extern int mount_main(int argc, char **argv)
                numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
                if (numfilesystems<0)
                        fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
-               mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
+               mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
                
                /* Grab the list of mounted filesystems */
                if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
index ae33e32..a326bc5 100644 (file)
@@ -229,7 +229,7 @@ extern int ps_main(int argc, char **argv)
         * some new processes start up while we wait. The kernel will
         * just ignore any extras if we give it too many, and will trunc.
         * the list if we give it too few.  */
-       pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+       pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
        pid_array[0] = num_pids+10;
 
        /* Now grab the pid list */
diff --git a/ps.c b/ps.c
index ae33e32..a326bc5 100644 (file)
--- a/ps.c
+++ b/ps.c
@@ -229,7 +229,7 @@ extern int ps_main(int argc, char **argv)
         * some new processes start up while we wait. The kernel will
         * just ignore any extras if we give it too many, and will trunc.
         * the list if we give it too few.  */
-       pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+       pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
        pid_array[0] = num_pids+10;
 
        /* Now grab the pid list */
diff --git a/sed.c b/sed.c
index f3c3262..0e0d7f5 100644 (file)
--- a/sed.c
+++ b/sed.c
@@ -44,7 +44,6 @@
 */
 
 #include <stdio.h>
-#include <stdlib.h> /* for realloc() */
 #include <unistd.h> /* for getopt() */
 #include <regex.h>
 #include <string.h> /* for strdup() */
@@ -457,7 +456,7 @@ static void add_cmd_str(const char *cmdstr)
                        continue;
                }
                /* grow the array */
-               sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
+               sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
                /* zero new element */
                memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
                /* load command string into new array element, get remainder */
@@ -481,7 +480,7 @@ static void load_cmd_file(char *filename)
                /* if a line ends with '\' it needs the next line appended to it */
                while (line[strlen(line)-2] == '\\' &&
                                (nextline = get_line_from_file(cmdfile)) != NULL) {
-                       line = realloc(line, strlen(line) + strlen(nextline) + 1);
+                       line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
                        strcat(line, nextline);
                        free(nextline);
                }
index 042064f..04abc93 100644 (file)
@@ -246,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
 char** exe_n_cwd_tab_completion(char* command, int *num_matches)
 {
        char *dirName;
-       char **matches = (char **) NULL;
+       char **matches;
        DIR *dir;
        struct dirent *next;
                        
-       matches = malloc( sizeof(char*)*50);
+       matches = xmalloc( sizeof(char*)*50);
 
        /* Stick a wildcard onto the command, for later use */
        strcat( command, "*");
@@ -273,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
                /* See if this matches */
                if (check_wildcard_match(next->d_name, command) == TRUE) {
                        /* Cool, found a match.  Add it to the list */
-                       matches[*num_matches] = malloc(strlen(next->d_name)+1);
+                       matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
                        strcpy( matches[*num_matches], next->d_name);
                        ++*num_matches;
                        //matches = realloc( matches, sizeof(char*)*(*num_matches));
@@ -302,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
 
                /* Make a local copy of the string -- up 
                 * to the position of the cursor */
-               matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
+               matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
                strncpy(matchBuf, command, cursor);
                tmp=matchBuf;
 
@@ -670,8 +670,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
 
                if (!h) {
                        /* No previous history -- this memory is never freed */
-                       h = his_front = malloc(sizeof(struct history));
-                       h->n = malloc(sizeof(struct history));
+                       h = his_front = xmalloc(sizeof(struct history));
+                       h->n = xmalloc(sizeof(struct history));
 
                        h->p = NULL;
                        h->s = strdup(command);
@@ -682,7 +682,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
                        history_counter++;
                } else {
                        /* Add a new history command -- this memory is never freed */
-                       h->n = malloc(sizeof(struct history));
+                       h->n = xmalloc(sizeof(struct history));
 
                        h->n->p = h;
                        h->n->n = NULL;
diff --git a/sort.c b/sort.c
index 6af5c4d..a74f96a 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -64,7 +64,7 @@ static const int max = 1024;
 static Line *line_alloc()
 {
        Line *self;
-       self = malloc(1 * sizeof(Line));
+       self = xmalloc(1 * sizeof(Line));
        return self;
 }
 
@@ -76,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
 
        if ((cstring = get_line_from_file(src))) {
                self = line_alloc();
-               if (self == NULL) {
-                       return NULL;
-               }
                self->data = cstring;
                self->next = NULL;
                return self;
@@ -173,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
        Line *line;
 
        /* mallocate array of Line*s */
-       self->sorted = (Line **) malloc(self->len * sizeof(Line *));
-       if (self->sorted == NULL) {
-               return NULL;
-       }
+       self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
 
        /* fill array w/ List's contents */
        i = 0;
@@ -294,4 +288,4 @@ int sort_main(int argc, char **argv)
        return(0);
 }
 
-/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */
+/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */
diff --git a/tail.c b/tail.c
index c940bfe..dcb4f67 100644 (file)
--- a/tail.c
+++ b/tail.c
@@ -87,12 +87,12 @@ int tail_stream(int fd)
                        ssize_t f_size=0;
 
                        bs=BUFSIZ;
-                       line=malloc(bs);
+                       line=xmalloc(bs);
                        while(1) {
                                bytes_read=read(fd,line,bs);
                                if(bytes_read<=0)
                                        break;
-                               buffer=realloc(buffer,f_size+bytes_read);
+                               buffer=xrealloc(buffer,f_size+bytes_read);
                                memcpy(&buffer[f_size],line,bytes_read);
                                filelocation=f_size+=bytes_read;
                        }
@@ -150,8 +150,8 @@ int tail_stream(int fd)
 void add_file(char *name)
 {
        ++n_files;
-       files = realloc(files, n_files);
-       files[n_files - 1] = (char *) malloc(strlen(name) + 1);
+       files = xrealloc(files, n_files);
+       files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
        strcpy(files[n_files - 1], name);
 }
 
@@ -268,13 +268,13 @@ int tail_main(int argc, char **argv)
                units=-11;
        if(units>0)
                units--;
-       fd=malloc(sizeof(int)*n_files);
+       fd=xmalloc(sizeof(int)*n_files);
        if (n_files == 1)
 #ifndef BB_FEATURE_SIMPLE_TAIL
                if (!verbose)
 #endif
                        show_headers = 0;
-       buffer=malloc(BUFSIZ);
+       buffer=xmalloc(BUFSIZ);
        for (test = 0; test < n_files; test++) {
                if (show_headers)
                        printf("==> %s <==\n", files[test]);
diff --git a/test.c b/test.c
index 6dde718..a2bec44 100644 (file)
--- a/test.c
+++ b/test.c
@@ -555,9 +555,7 @@ static void
 initialize_group_array ()
 {
        ngroups = getgroups(0, NULL);
-       if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
-               fatalError("Out of space\n");
-
+       group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
        getgroups(ngroups, group_array);
 }
 
index b4f5746..15ab5c9 100644 (file)
@@ -273,7 +273,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
                numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
                if (numfilesystems<0)
                        fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
-               fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
+               fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
 
                /* Grab the list of available filesystems */
                status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
@@ -343,7 +343,7 @@ extern int mount_main(int argc, char **argv)
                numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
                if (numfilesystems<0)
                        fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
-               mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
+               mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
                
                /* Grab the list of mounted filesystems */
                if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
index 8827b4a..4defbfc 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -1290,7 +1290,7 @@ extern pid_t* findPidByName( char* pidName)
         * some new processes start up while we wait. The kernel will
         * just ignore any extras if we give it too many, and will trunc.
         * the list if we give it too few.  */
-       pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+       pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
        pid_array[0] = num_pids+10;
 
        /* Now grab the pid list */
@@ -1316,9 +1316,7 @@ extern pid_t* findPidByName( char* pidName)
 
                if ((strstr(info.command_line, pidName) != NULL)
                                && (strlen(pidName) == strlen(info.command_line))) {
-                       pidList=realloc( pidList, sizeof(pid_t) * (j+2));
-                       if (pidList==NULL)
-                               fatalError(memory_exhausted);
+                       pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
                        pidList[j++]=info.pid;
                }
        }
@@ -1389,9 +1387,7 @@ extern pid_t* findPidByName( char* pidName)
 
                if ((strstr(p, pidName) != NULL)
                                && (strlen(pidName) == strlen(p))) {
-                       pidList=realloc( pidList, sizeof(pid_t) * (i+2));
-                       if (pidList==NULL)
-                               fatalError(memory_exhausted);
+                       pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
                        pidList[i++]=strtol(next->d_name, NULL, 0);
                }
        }
@@ -1624,7 +1620,7 @@ extern char *get_line_from_file(FILE *file)
                        break;
                /* grow the line buffer as necessary */
                if (idx > linebufsz-2)
-                       linebuf = realloc(linebuf, linebufsz += GROWBY);
+                       linebuf = xrealloc(linebuf, linebufsz += GROWBY);
                linebuf[idx++] = (char)ch;
                if ((char)ch == '\n')
                        break;
diff --git a/which.c b/which.c
index b3fd934..07c0e0d 100644 (file)
--- a/which.c
+++ b/which.c
@@ -40,7 +40,7 @@ extern int which_main(int argc, char **argv)
        if (!path_list)
                path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
 
-       path_parsed = malloc (strlen(path_list) + 1);
+       path_parsed = xmalloc (strlen(path_list) + 1);
        strcpy (path_parsed, path_list);
 
        /* Replace colons with zeros in path_parsed and count them */