aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-09-13 02:46:14 +0000
committerMatt Kraai <kraai@debian.org>2000-09-13 02:46:14 +0000
commit322ae93a5e0b78b65831f9fd87fd456eb84d21a1 (patch)
tree5b967e1d873ff6eff8296bf9fda73825f0c55884
parentb89075298edf0a471b9046b1f3c8a936e18ead20 (diff)
downloadbusybox-w32-322ae93a5e0b78b65831f9fd87fd456eb84d21a1.tar.gz
busybox-w32-322ae93a5e0b78b65831f9fd87fd456eb84d21a1.tar.bz2
busybox-w32-322ae93a5e0b78b65831f9fd87fd456eb84d21a1.zip
Fix calls to {m,c,re}alloc so that they use x{m,c,re}alloc instead of
segfaulting or handling errors the same way themselves.
-rw-r--r--ar.c14
-rw-r--r--archival/ar.c14
-rw-r--r--cmdedit.c14
-rw-r--r--console-tools/loadfont.c6
-rw-r--r--console-tools/loadkmap.c6
-rw-r--r--coreutils/ln.c2
-rw-r--r--coreutils/sort.c12
-rw-r--r--coreutils/tail.c12
-rw-r--r--coreutils/test.c4
-rw-r--r--editors/sed.c5
-rw-r--r--findutils/which.c2
-rw-r--r--ln.c2
-rw-r--r--loadfont.c6
-rw-r--r--loadkmap.c6
-rw-r--r--mount.c4
-rw-r--r--procps/ps.c2
-rw-r--r--ps.c2
-rw-r--r--sed.c5
-rw-r--r--shell/cmdedit.c14
-rw-r--r--sort.c12
-rw-r--r--tail.c12
-rw-r--r--test.c4
-rw-r--r--util-linux/mount.c4
-rw-r--r--utility.c12
-rw-r--r--which.c2
25 files changed, 70 insertions, 108 deletions
diff --git a/ar.c b/ar.c
index d82763df1..241c1fac2 100644
--- a/ar.c
+++ b/ar.c
@@ -246,7 +246,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
246 headerL_t *list; 246 headerL_t *list;
247 off_t initialOffset; 247 off_t initialOffset;
248 248
249 list = (headerL_t *) malloc(sizeof(headerL_t)); 249 list = (headerL_t *) xmalloc(sizeof(headerL_t));
250 initialOffset=lseek(srcFd, 0, SEEK_CUR); 250 initialOffset=lseek(srcFd, 0, SEEK_CUR);
251 if (checkArMagic(srcFd)==TRUE) 251 if (checkArMagic(srcFd)==TRUE)
252 ar=TRUE; 252 ar=TRUE;
@@ -258,7 +258,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
258 if (tar==TRUE) { 258 if (tar==TRUE) {
259 while(readTarHeader(srcFd, list)==TRUE) { 259 while(readTarHeader(srcFd, list)==TRUE) {
260 off_t tarOffset; 260 off_t tarOffset;
261 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 261 list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
262 *list->next = *head; 262 *list->next = *head;
263 *head = *list; 263 *head = *list;
264 264
@@ -282,7 +282,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
282 if (readArEntry(srcFd, list) == FALSE) 282 if (readArEntry(srcFd, list) == FALSE)
283 return(head); 283 return(head);
284 } 284 }
285 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 285 list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
286 *list->next = *head; 286 *list->next = *head;
287 *head = *list; 287 *head = *list;
288 /* recursive check for sub-archives */ 288 /* recursive check for sub-archives */
@@ -349,9 +349,9 @@ extern int ar_main(int argc, char **argv)
349 return (FALSE); 349 return (FALSE);
350 } 350 }
351 optind++; 351 optind++;
352 entry = (headerL_t *) malloc(sizeof(headerL_t)); 352 entry = (headerL_t *) xmalloc(sizeof(headerL_t));
353 header = (headerL_t *) malloc(sizeof(headerL_t)); 353 header = (headerL_t *) xmalloc(sizeof(headerL_t));
354 extractList = (headerL_t *) malloc(sizeof(headerL_t)); 354 extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
355 355
356 header = getHeaders(srcFd, header, funct); 356 header = getHeaders(srcFd, header, funct);
357 /* find files to extract or display */ 357 /* find files to extract or display */
@@ -359,7 +359,7 @@ extern int ar_main(int argc, char **argv)
359 /* only handle specified files */ 359 /* only handle specified files */
360 while(optind < argc) { 360 while(optind < argc) {
361 if ( (entry = findEntry(header, argv[optind])) != NULL) { 361 if ( (entry = findEntry(header, argv[optind])) != NULL) {
362 entry->next = (headerL_t *) malloc(sizeof(headerL_t)); 362 entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
363 *entry->next = *extractList; 363 *entry->next = *extractList;
364 *extractList = *entry; 364 *extractList = *entry;
365 } 365 }
diff --git a/archival/ar.c b/archival/ar.c
index d82763df1..241c1fac2 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -246,7 +246,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
246 headerL_t *list; 246 headerL_t *list;
247 off_t initialOffset; 247 off_t initialOffset;
248 248
249 list = (headerL_t *) malloc(sizeof(headerL_t)); 249 list = (headerL_t *) xmalloc(sizeof(headerL_t));
250 initialOffset=lseek(srcFd, 0, SEEK_CUR); 250 initialOffset=lseek(srcFd, 0, SEEK_CUR);
251 if (checkArMagic(srcFd)==TRUE) 251 if (checkArMagic(srcFd)==TRUE)
252 ar=TRUE; 252 ar=TRUE;
@@ -258,7 +258,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
258 if (tar==TRUE) { 258 if (tar==TRUE) {
259 while(readTarHeader(srcFd, list)==TRUE) { 259 while(readTarHeader(srcFd, list)==TRUE) {
260 off_t tarOffset; 260 off_t tarOffset;
261 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 261 list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
262 *list->next = *head; 262 *list->next = *head;
263 *head = *list; 263 *head = *list;
264 264
@@ -282,7 +282,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
282 if (readArEntry(srcFd, list) == FALSE) 282 if (readArEntry(srcFd, list) == FALSE)
283 return(head); 283 return(head);
284 } 284 }
285 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 285 list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
286 *list->next = *head; 286 *list->next = *head;
287 *head = *list; 287 *head = *list;
288 /* recursive check for sub-archives */ 288 /* recursive check for sub-archives */
@@ -349,9 +349,9 @@ extern int ar_main(int argc, char **argv)
349 return (FALSE); 349 return (FALSE);
350 } 350 }
351 optind++; 351 optind++;
352 entry = (headerL_t *) malloc(sizeof(headerL_t)); 352 entry = (headerL_t *) xmalloc(sizeof(headerL_t));
353 header = (headerL_t *) malloc(sizeof(headerL_t)); 353 header = (headerL_t *) xmalloc(sizeof(headerL_t));
354 extractList = (headerL_t *) malloc(sizeof(headerL_t)); 354 extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
355 355
356 header = getHeaders(srcFd, header, funct); 356 header = getHeaders(srcFd, header, funct);
357 /* find files to extract or display */ 357 /* find files to extract or display */
@@ -359,7 +359,7 @@ extern int ar_main(int argc, char **argv)
359 /* only handle specified files */ 359 /* only handle specified files */
360 while(optind < argc) { 360 while(optind < argc) {
361 if ( (entry = findEntry(header, argv[optind])) != NULL) { 361 if ( (entry = findEntry(header, argv[optind])) != NULL) {
362 entry->next = (headerL_t *) malloc(sizeof(headerL_t)); 362 entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
363 *entry->next = *extractList; 363 *entry->next = *extractList;
364 *extractList = *entry; 364 *extractList = *entry;
365 } 365 }
diff --git a/cmdedit.c b/cmdedit.c
index 042064f1e..04abc938c 100644
--- a/cmdedit.c
+++ b/cmdedit.c
@@ -246,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
246char** exe_n_cwd_tab_completion(char* command, int *num_matches) 246char** exe_n_cwd_tab_completion(char* command, int *num_matches)
247{ 247{
248 char *dirName; 248 char *dirName;
249 char **matches = (char **) NULL; 249 char **matches;
250 DIR *dir; 250 DIR *dir;
251 struct dirent *next; 251 struct dirent *next;
252 252
253 matches = malloc( sizeof(char*)*50); 253 matches = xmalloc( sizeof(char*)*50);
254 254
255 /* Stick a wildcard onto the command, for later use */ 255 /* Stick a wildcard onto the command, for later use */
256 strcat( command, "*"); 256 strcat( command, "*");
@@ -273,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
273 /* See if this matches */ 273 /* See if this matches */
274 if (check_wildcard_match(next->d_name, command) == TRUE) { 274 if (check_wildcard_match(next->d_name, command) == TRUE) {
275 /* Cool, found a match. Add it to the list */ 275 /* Cool, found a match. Add it to the list */
276 matches[*num_matches] = malloc(strlen(next->d_name)+1); 276 matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
277 strcpy( matches[*num_matches], next->d_name); 277 strcpy( matches[*num_matches], next->d_name);
278 ++*num_matches; 278 ++*num_matches;
279 //matches = realloc( matches, sizeof(char*)*(*num_matches)); 279 //matches = realloc( matches, sizeof(char*)*(*num_matches));
@@ -302,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
302 302
303 /* Make a local copy of the string -- up 303 /* Make a local copy of the string -- up
304 * to the position of the cursor */ 304 * to the position of the cursor */
305 matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); 305 matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
306 strncpy(matchBuf, command, cursor); 306 strncpy(matchBuf, command, cursor);
307 tmp=matchBuf; 307 tmp=matchBuf;
308 308
@@ -670,8 +670,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
670 670
671 if (!h) { 671 if (!h) {
672 /* No previous history -- this memory is never freed */ 672 /* No previous history -- this memory is never freed */
673 h = his_front = malloc(sizeof(struct history)); 673 h = his_front = xmalloc(sizeof(struct history));
674 h->n = malloc(sizeof(struct history)); 674 h->n = xmalloc(sizeof(struct history));
675 675
676 h->p = NULL; 676 h->p = NULL;
677 h->s = strdup(command); 677 h->s = strdup(command);
@@ -682,7 +682,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
682 history_counter++; 682 history_counter++;
683 } else { 683 } else {
684 /* Add a new history command -- this memory is never freed */ 684 /* Add a new history command -- this memory is never freed */
685 h->n = malloc(sizeof(struct history)); 685 h->n = xmalloc(sizeof(struct history));
686 686
687 h->n->p = h; 687 h->n->p = h;
688 h->n->n = NULL; 688 h->n->n = NULL;
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c
index 927c2bad4..e93ca3186 100644
--- a/console-tools/loadfont.c
+++ b/console-tools/loadfont.c
@@ -102,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
102 u_short unicode; 102 u_short unicode;
103 103
104 maxct = tailsz; /* more than enough */ 104 maxct = tailsz; /* more than enough */
105 up = (struct unipair *) malloc(maxct * sizeof(struct unipair)); 105 up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
106 106
107 if (!up) {
108 errorMsg("Out of memory?\n");
109 exit(1);
110 }
111 for (glyph = 0; glyph < fontsize; glyph++) { 107 for (glyph = 0; glyph < fontsize; glyph++) {
112 while (tailsz >= 2) { 108 while (tailsz >= 2) {
113 unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; 109 unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c
index 488585f9c..2321a1ede 100644
--- a/console-tools/loadkmap.c
+++ b/console-tools/loadkmap.c
@@ -67,11 +67,7 @@ int loadkmap_main(int argc, char **argv)
67 exit(FALSE); 67 exit(FALSE);
68 } 68 }
69 69
70 ibuff = (u_short *) malloc(ibuffsz); 70 ibuff = (u_short *) xmalloc(ibuffsz);
71 if (!ibuff) {
72 errorMsg("Out of memory.\n");
73 exit(FALSE);
74 }
75 71
76 for (i = 0; i < MAX_NR_KEYMAPS; i++) { 72 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
77 if (flags[i] == 1) { 73 if (flags[i] == 1) {
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 8b8fa1c58..d5f44ea4c 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -90,7 +90,7 @@ extern int ln_main(int argc, char **argv)
90 90
91 if (linkIntoDirFlag == TRUE) { 91 if (linkIntoDirFlag == TRUE) {
92 char *baseName = get_last_path_component(*argv); 92 char *baseName = get_last_path_component(*argv);
93 linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2); 93 linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
94 strcpy(linkName, dirName); 94 strcpy(linkName, dirName);
95 if(dirName[strlen(dirName)-1] != '/') 95 if(dirName[strlen(dirName)-1] != '/')
96 strcat(linkName, "/"); 96 strcat(linkName, "/");
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 6af5c4df3..a74f96ad0 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -64,7 +64,7 @@ static const int max = 1024;
64static Line *line_alloc() 64static Line *line_alloc()
65{ 65{
66 Line *self; 66 Line *self;
67 self = malloc(1 * sizeof(Line)); 67 self = xmalloc(1 * sizeof(Line));
68 return self; 68 return self;
69} 69}
70 70
@@ -76,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
76 76
77 if ((cstring = get_line_from_file(src))) { 77 if ((cstring = get_line_from_file(src))) {
78 self = line_alloc(); 78 self = line_alloc();
79 if (self == NULL) {
80 return NULL;
81 }
82 self->data = cstring; 79 self->data = cstring;
83 self->next = NULL; 80 self->next = NULL;
84 return self; 81 return self;
@@ -173,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
173 Line *line; 170 Line *line;
174 171
175 /* mallocate array of Line*s */ 172 /* mallocate array of Line*s */
176 self->sorted = (Line **) malloc(self->len * sizeof(Line *)); 173 self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
177 if (self->sorted == NULL) {
178 return NULL;
179 }
180 174
181 /* fill array w/ List's contents */ 175 /* fill array w/ List's contents */
182 i = 0; 176 i = 0;
@@ -294,4 +288,4 @@ int sort_main(int argc, char **argv)
294 return(0); 288 return(0);
295} 289}
296 290
297/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */ 291/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */
diff --git a/coreutils/tail.c b/coreutils/tail.c
index c940bfef7..dcb4f6742 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -87,12 +87,12 @@ int tail_stream(int fd)
87 ssize_t f_size=0; 87 ssize_t f_size=0;
88 88
89 bs=BUFSIZ; 89 bs=BUFSIZ;
90 line=malloc(bs); 90 line=xmalloc(bs);
91 while(1) { 91 while(1) {
92 bytes_read=read(fd,line,bs); 92 bytes_read=read(fd,line,bs);
93 if(bytes_read<=0) 93 if(bytes_read<=0)
94 break; 94 break;
95 buffer=realloc(buffer,f_size+bytes_read); 95 buffer=xrealloc(buffer,f_size+bytes_read);
96 memcpy(&buffer[f_size],line,bytes_read); 96 memcpy(&buffer[f_size],line,bytes_read);
97 filelocation=f_size+=bytes_read; 97 filelocation=f_size+=bytes_read;
98 } 98 }
@@ -150,8 +150,8 @@ int tail_stream(int fd)
150void add_file(char *name) 150void add_file(char *name)
151{ 151{
152 ++n_files; 152 ++n_files;
153 files = realloc(files, n_files); 153 files = xrealloc(files, n_files);
154 files[n_files - 1] = (char *) malloc(strlen(name) + 1); 154 files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
155 strcpy(files[n_files - 1], name); 155 strcpy(files[n_files - 1], name);
156} 156}
157 157
@@ -268,13 +268,13 @@ int tail_main(int argc, char **argv)
268 units=-11; 268 units=-11;
269 if(units>0) 269 if(units>0)
270 units--; 270 units--;
271 fd=malloc(sizeof(int)*n_files); 271 fd=xmalloc(sizeof(int)*n_files);
272 if (n_files == 1) 272 if (n_files == 1)
273#ifndef BB_FEATURE_SIMPLE_TAIL 273#ifndef BB_FEATURE_SIMPLE_TAIL
274 if (!verbose) 274 if (!verbose)
275#endif 275#endif
276 show_headers = 0; 276 show_headers = 0;
277 buffer=malloc(BUFSIZ); 277 buffer=xmalloc(BUFSIZ);
278 for (test = 0; test < n_files; test++) { 278 for (test = 0; test < n_files; test++) {
279 if (show_headers) 279 if (show_headers)
280 printf("==> %s <==\n", files[test]); 280 printf("==> %s <==\n", files[test]);
diff --git a/coreutils/test.c b/coreutils/test.c
index 6dde718c7..a2bec4492 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -555,9 +555,7 @@ static void
555initialize_group_array () 555initialize_group_array ()
556{ 556{
557 ngroups = getgroups(0, NULL); 557 ngroups = getgroups(0, NULL);
558 if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL) 558 group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
559 fatalError("Out of space\n");
560
561 getgroups(ngroups, group_array); 559 getgroups(ngroups, group_array);
562} 560}
563 561
diff --git a/editors/sed.c b/editors/sed.c
index f3c3262e4..0e0d7f58c 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -44,7 +44,6 @@
44*/ 44*/
45 45
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> /* for realloc() */
48#include <unistd.h> /* for getopt() */ 47#include <unistd.h> /* for getopt() */
49#include <regex.h> 48#include <regex.h>
50#include <string.h> /* for strdup() */ 49#include <string.h> /* for strdup() */
@@ -457,7 +456,7 @@ static void add_cmd_str(const char *cmdstr)
457 continue; 456 continue;
458 } 457 }
459 /* grow the array */ 458 /* grow the array */
460 sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds)); 459 sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
461 /* zero new element */ 460 /* zero new element */
462 memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd)); 461 memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
463 /* load command string into new array element, get remainder */ 462 /* load command string into new array element, get remainder */
@@ -481,7 +480,7 @@ static void load_cmd_file(char *filename)
481 /* if a line ends with '\' it needs the next line appended to it */ 480 /* if a line ends with '\' it needs the next line appended to it */
482 while (line[strlen(line)-2] == '\\' && 481 while (line[strlen(line)-2] == '\\' &&
483 (nextline = get_line_from_file(cmdfile)) != NULL) { 482 (nextline = get_line_from_file(cmdfile)) != NULL) {
484 line = realloc(line, strlen(line) + strlen(nextline) + 1); 483 line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
485 strcat(line, nextline); 484 strcat(line, nextline);
486 free(nextline); 485 free(nextline);
487 } 486 }
diff --git a/findutils/which.c b/findutils/which.c
index b3fd934d7..07c0e0d85 100644
--- a/findutils/which.c
+++ b/findutils/which.c
@@ -40,7 +40,7 @@ extern int which_main(int argc, char **argv)
40 if (!path_list) 40 if (!path_list)
41 path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"; 41 path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
42 42
43 path_parsed = malloc (strlen(path_list) + 1); 43 path_parsed = xmalloc (strlen(path_list) + 1);
44 strcpy (path_parsed, path_list); 44 strcpy (path_parsed, path_list);
45 45
46 /* Replace colons with zeros in path_parsed and count them */ 46 /* Replace colons with zeros in path_parsed and count them */
diff --git a/ln.c b/ln.c
index 8b8fa1c58..d5f44ea4c 100644
--- a/ln.c
+++ b/ln.c
@@ -90,7 +90,7 @@ extern int ln_main(int argc, char **argv)
90 90
91 if (linkIntoDirFlag == TRUE) { 91 if (linkIntoDirFlag == TRUE) {
92 char *baseName = get_last_path_component(*argv); 92 char *baseName = get_last_path_component(*argv);
93 linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2); 93 linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
94 strcpy(linkName, dirName); 94 strcpy(linkName, dirName);
95 if(dirName[strlen(dirName)-1] != '/') 95 if(dirName[strlen(dirName)-1] != '/')
96 strcat(linkName, "/"); 96 strcat(linkName, "/");
diff --git a/loadfont.c b/loadfont.c
index 927c2bad4..e93ca3186 100644
--- a/loadfont.c
+++ b/loadfont.c
@@ -102,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
102 u_short unicode; 102 u_short unicode;
103 103
104 maxct = tailsz; /* more than enough */ 104 maxct = tailsz; /* more than enough */
105 up = (struct unipair *) malloc(maxct * sizeof(struct unipair)); 105 up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
106 106
107 if (!up) {
108 errorMsg("Out of memory?\n");
109 exit(1);
110 }
111 for (glyph = 0; glyph < fontsize; glyph++) { 107 for (glyph = 0; glyph < fontsize; glyph++) {
112 while (tailsz >= 2) { 108 while (tailsz >= 2) {
113 unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; 109 unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
diff --git a/loadkmap.c b/loadkmap.c
index 488585f9c..2321a1ede 100644
--- a/loadkmap.c
+++ b/loadkmap.c
@@ -67,11 +67,7 @@ int loadkmap_main(int argc, char **argv)
67 exit(FALSE); 67 exit(FALSE);
68 } 68 }
69 69
70 ibuff = (u_short *) malloc(ibuffsz); 70 ibuff = (u_short *) xmalloc(ibuffsz);
71 if (!ibuff) {
72 errorMsg("Out of memory.\n");
73 exit(FALSE);
74 }
75 71
76 for (i = 0; i < MAX_NR_KEYMAPS; i++) { 72 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
77 if (flags[i] == 1) { 73 if (flags[i] == 1) {
diff --git a/mount.c b/mount.c
index b4f5746bc..15ab5c997 100644
--- a/mount.c
+++ b/mount.c
@@ -273,7 +273,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
273 numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); 273 numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
274 if (numfilesystems<0) 274 if (numfilesystems<0)
275 fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno)); 275 fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
276 fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype)); 276 fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
277 277
278 /* Grab the list of available filesystems */ 278 /* Grab the list of available filesystems */
279 status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); 279 status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
@@ -343,7 +343,7 @@ extern int mount_main(int argc, char **argv)
343 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS); 343 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
344 if (numfilesystems<0) 344 if (numfilesystems<0)
345 fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno)); 345 fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
346 mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent)); 346 mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
347 347
348 /* Grab the list of mounted filesystems */ 348 /* Grab the list of mounted filesystems */
349 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) 349 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
diff --git a/procps/ps.c b/procps/ps.c
index ae33e3262..a326bc546 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -229,7 +229,7 @@ extern int ps_main(int argc, char **argv)
229 * some new processes start up while we wait. The kernel will 229 * some new processes start up while we wait. The kernel will
230 * just ignore any extras if we give it too many, and will trunc. 230 * just ignore any extras if we give it too many, and will trunc.
231 * the list if we give it too few. */ 231 * the list if we give it too few. */
232 pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t)); 232 pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
233 pid_array[0] = num_pids+10; 233 pid_array[0] = num_pids+10;
234 234
235 /* Now grab the pid list */ 235 /* Now grab the pid list */
diff --git a/ps.c b/ps.c
index ae33e3262..a326bc546 100644
--- a/ps.c
+++ b/ps.c
@@ -229,7 +229,7 @@ extern int ps_main(int argc, char **argv)
229 * some new processes start up while we wait. The kernel will 229 * some new processes start up while we wait. The kernel will
230 * just ignore any extras if we give it too many, and will trunc. 230 * just ignore any extras if we give it too many, and will trunc.
231 * the list if we give it too few. */ 231 * the list if we give it too few. */
232 pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t)); 232 pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
233 pid_array[0] = num_pids+10; 233 pid_array[0] = num_pids+10;
234 234
235 /* Now grab the pid list */ 235 /* Now grab the pid list */
diff --git a/sed.c b/sed.c
index f3c3262e4..0e0d7f58c 100644
--- a/sed.c
+++ b/sed.c
@@ -44,7 +44,6 @@
44*/ 44*/
45 45
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> /* for realloc() */
48#include <unistd.h> /* for getopt() */ 47#include <unistd.h> /* for getopt() */
49#include <regex.h> 48#include <regex.h>
50#include <string.h> /* for strdup() */ 49#include <string.h> /* for strdup() */
@@ -457,7 +456,7 @@ static void add_cmd_str(const char *cmdstr)
457 continue; 456 continue;
458 } 457 }
459 /* grow the array */ 458 /* grow the array */
460 sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds)); 459 sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
461 /* zero new element */ 460 /* zero new element */
462 memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd)); 461 memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
463 /* load command string into new array element, get remainder */ 462 /* load command string into new array element, get remainder */
@@ -481,7 +480,7 @@ static void load_cmd_file(char *filename)
481 /* if a line ends with '\' it needs the next line appended to it */ 480 /* if a line ends with '\' it needs the next line appended to it */
482 while (line[strlen(line)-2] == '\\' && 481 while (line[strlen(line)-2] == '\\' &&
483 (nextline = get_line_from_file(cmdfile)) != NULL) { 482 (nextline = get_line_from_file(cmdfile)) != NULL) {
484 line = realloc(line, strlen(line) + strlen(nextline) + 1); 483 line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
485 strcat(line, nextline); 484 strcat(line, nextline);
486 free(nextline); 485 free(nextline);
487 } 486 }
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 042064f1e..04abc938c 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -246,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
246char** exe_n_cwd_tab_completion(char* command, int *num_matches) 246char** exe_n_cwd_tab_completion(char* command, int *num_matches)
247{ 247{
248 char *dirName; 248 char *dirName;
249 char **matches = (char **) NULL; 249 char **matches;
250 DIR *dir; 250 DIR *dir;
251 struct dirent *next; 251 struct dirent *next;
252 252
253 matches = malloc( sizeof(char*)*50); 253 matches = xmalloc( sizeof(char*)*50);
254 254
255 /* Stick a wildcard onto the command, for later use */ 255 /* Stick a wildcard onto the command, for later use */
256 strcat( command, "*"); 256 strcat( command, "*");
@@ -273,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
273 /* See if this matches */ 273 /* See if this matches */
274 if (check_wildcard_match(next->d_name, command) == TRUE) { 274 if (check_wildcard_match(next->d_name, command) == TRUE) {
275 /* Cool, found a match. Add it to the list */ 275 /* Cool, found a match. Add it to the list */
276 matches[*num_matches] = malloc(strlen(next->d_name)+1); 276 matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
277 strcpy( matches[*num_matches], next->d_name); 277 strcpy( matches[*num_matches], next->d_name);
278 ++*num_matches; 278 ++*num_matches;
279 //matches = realloc( matches, sizeof(char*)*(*num_matches)); 279 //matches = realloc( matches, sizeof(char*)*(*num_matches));
@@ -302,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
302 302
303 /* Make a local copy of the string -- up 303 /* Make a local copy of the string -- up
304 * to the position of the cursor */ 304 * to the position of the cursor */
305 matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); 305 matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
306 strncpy(matchBuf, command, cursor); 306 strncpy(matchBuf, command, cursor);
307 tmp=matchBuf; 307 tmp=matchBuf;
308 308
@@ -670,8 +670,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
670 670
671 if (!h) { 671 if (!h) {
672 /* No previous history -- this memory is never freed */ 672 /* No previous history -- this memory is never freed */
673 h = his_front = malloc(sizeof(struct history)); 673 h = his_front = xmalloc(sizeof(struct history));
674 h->n = malloc(sizeof(struct history)); 674 h->n = xmalloc(sizeof(struct history));
675 675
676 h->p = NULL; 676 h->p = NULL;
677 h->s = strdup(command); 677 h->s = strdup(command);
@@ -682,7 +682,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
682 history_counter++; 682 history_counter++;
683 } else { 683 } else {
684 /* Add a new history command -- this memory is never freed */ 684 /* Add a new history command -- this memory is never freed */
685 h->n = malloc(sizeof(struct history)); 685 h->n = xmalloc(sizeof(struct history));
686 686
687 h->n->p = h; 687 h->n->p = h;
688 h->n->n = NULL; 688 h->n->n = NULL;
diff --git a/sort.c b/sort.c
index 6af5c4df3..a74f96ad0 100644
--- a/sort.c
+++ b/sort.c
@@ -64,7 +64,7 @@ static const int max = 1024;
64static Line *line_alloc() 64static Line *line_alloc()
65{ 65{
66 Line *self; 66 Line *self;
67 self = malloc(1 * sizeof(Line)); 67 self = xmalloc(1 * sizeof(Line));
68 return self; 68 return self;
69} 69}
70 70
@@ -76,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
76 76
77 if ((cstring = get_line_from_file(src))) { 77 if ((cstring = get_line_from_file(src))) {
78 self = line_alloc(); 78 self = line_alloc();
79 if (self == NULL) {
80 return NULL;
81 }
82 self->data = cstring; 79 self->data = cstring;
83 self->next = NULL; 80 self->next = NULL;
84 return self; 81 return self;
@@ -173,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
173 Line *line; 170 Line *line;
174 171
175 /* mallocate array of Line*s */ 172 /* mallocate array of Line*s */
176 self->sorted = (Line **) malloc(self->len * sizeof(Line *)); 173 self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
177 if (self->sorted == NULL) {
178 return NULL;
179 }
180 174
181 /* fill array w/ List's contents */ 175 /* fill array w/ List's contents */
182 i = 0; 176 i = 0;
@@ -294,4 +288,4 @@ int sort_main(int argc, char **argv)
294 return(0); 288 return(0);
295} 289}
296 290
297/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */ 291/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */
diff --git a/tail.c b/tail.c
index c940bfef7..dcb4f6742 100644
--- a/tail.c
+++ b/tail.c
@@ -87,12 +87,12 @@ int tail_stream(int fd)
87 ssize_t f_size=0; 87 ssize_t f_size=0;
88 88
89 bs=BUFSIZ; 89 bs=BUFSIZ;
90 line=malloc(bs); 90 line=xmalloc(bs);
91 while(1) { 91 while(1) {
92 bytes_read=read(fd,line,bs); 92 bytes_read=read(fd,line,bs);
93 if(bytes_read<=0) 93 if(bytes_read<=0)
94 break; 94 break;
95 buffer=realloc(buffer,f_size+bytes_read); 95 buffer=xrealloc(buffer,f_size+bytes_read);
96 memcpy(&buffer[f_size],line,bytes_read); 96 memcpy(&buffer[f_size],line,bytes_read);
97 filelocation=f_size+=bytes_read; 97 filelocation=f_size+=bytes_read;
98 } 98 }
@@ -150,8 +150,8 @@ int tail_stream(int fd)
150void add_file(char *name) 150void add_file(char *name)
151{ 151{
152 ++n_files; 152 ++n_files;
153 files = realloc(files, n_files); 153 files = xrealloc(files, n_files);
154 files[n_files - 1] = (char *) malloc(strlen(name) + 1); 154 files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
155 strcpy(files[n_files - 1], name); 155 strcpy(files[n_files - 1], name);
156} 156}
157 157
@@ -268,13 +268,13 @@ int tail_main(int argc, char **argv)
268 units=-11; 268 units=-11;
269 if(units>0) 269 if(units>0)
270 units--; 270 units--;
271 fd=malloc(sizeof(int)*n_files); 271 fd=xmalloc(sizeof(int)*n_files);
272 if (n_files == 1) 272 if (n_files == 1)
273#ifndef BB_FEATURE_SIMPLE_TAIL 273#ifndef BB_FEATURE_SIMPLE_TAIL
274 if (!verbose) 274 if (!verbose)
275#endif 275#endif
276 show_headers = 0; 276 show_headers = 0;
277 buffer=malloc(BUFSIZ); 277 buffer=xmalloc(BUFSIZ);
278 for (test = 0; test < n_files; test++) { 278 for (test = 0; test < n_files; test++) {
279 if (show_headers) 279 if (show_headers)
280 printf("==> %s <==\n", files[test]); 280 printf("==> %s <==\n", files[test]);
diff --git a/test.c b/test.c
index 6dde718c7..a2bec4492 100644
--- a/test.c
+++ b/test.c
@@ -555,9 +555,7 @@ static void
555initialize_group_array () 555initialize_group_array ()
556{ 556{
557 ngroups = getgroups(0, NULL); 557 ngroups = getgroups(0, NULL);
558 if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL) 558 group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
559 fatalError("Out of space\n");
560
561 getgroups(ngroups, group_array); 559 getgroups(ngroups, group_array);
562} 560}
563 561
diff --git a/util-linux/mount.c b/util-linux/mount.c
index b4f5746bc..15ab5c997 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -273,7 +273,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
273 numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); 273 numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
274 if (numfilesystems<0) 274 if (numfilesystems<0)
275 fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno)); 275 fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
276 fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype)); 276 fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
277 277
278 /* Grab the list of available filesystems */ 278 /* Grab the list of available filesystems */
279 status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); 279 status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
@@ -343,7 +343,7 @@ extern int mount_main(int argc, char **argv)
343 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS); 343 numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
344 if (numfilesystems<0) 344 if (numfilesystems<0)
345 fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno)); 345 fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
346 mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent)); 346 mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
347 347
348 /* Grab the list of mounted filesystems */ 348 /* Grab the list of mounted filesystems */
349 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) 349 if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
diff --git a/utility.c b/utility.c
index 8827b4a65..4defbfc81 100644
--- a/utility.c
+++ b/utility.c
@@ -1290,7 +1290,7 @@ extern pid_t* findPidByName( char* pidName)
1290 * some new processes start up while we wait. The kernel will 1290 * some new processes start up while we wait. The kernel will
1291 * just ignore any extras if we give it too many, and will trunc. 1291 * just ignore any extras if we give it too many, and will trunc.
1292 * the list if we give it too few. */ 1292 * the list if we give it too few. */
1293 pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t)); 1293 pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
1294 pid_array[0] = num_pids+10; 1294 pid_array[0] = num_pids+10;
1295 1295
1296 /* Now grab the pid list */ 1296 /* Now grab the pid list */
@@ -1316,9 +1316,7 @@ extern pid_t* findPidByName( char* pidName)
1316 1316
1317 if ((strstr(info.command_line, pidName) != NULL) 1317 if ((strstr(info.command_line, pidName) != NULL)
1318 && (strlen(pidName) == strlen(info.command_line))) { 1318 && (strlen(pidName) == strlen(info.command_line))) {
1319 pidList=realloc( pidList, sizeof(pid_t) * (j+2)); 1319 pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
1320 if (pidList==NULL)
1321 fatalError(memory_exhausted);
1322 pidList[j++]=info.pid; 1320 pidList[j++]=info.pid;
1323 } 1321 }
1324 } 1322 }
@@ -1389,9 +1387,7 @@ extern pid_t* findPidByName( char* pidName)
1389 1387
1390 if ((strstr(p, pidName) != NULL) 1388 if ((strstr(p, pidName) != NULL)
1391 && (strlen(pidName) == strlen(p))) { 1389 && (strlen(pidName) == strlen(p))) {
1392 pidList=realloc( pidList, sizeof(pid_t) * (i+2)); 1390 pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
1393 if (pidList==NULL)
1394 fatalError(memory_exhausted);
1395 pidList[i++]=strtol(next->d_name, NULL, 0); 1391 pidList[i++]=strtol(next->d_name, NULL, 0);
1396 } 1392 }
1397 } 1393 }
@@ -1624,7 +1620,7 @@ extern char *get_line_from_file(FILE *file)
1624 break; 1620 break;
1625 /* grow the line buffer as necessary */ 1621 /* grow the line buffer as necessary */
1626 if (idx > linebufsz-2) 1622 if (idx > linebufsz-2)
1627 linebuf = realloc(linebuf, linebufsz += GROWBY); 1623 linebuf = xrealloc(linebuf, linebufsz += GROWBY);
1628 linebuf[idx++] = (char)ch; 1624 linebuf[idx++] = (char)ch;
1629 if ((char)ch == '\n') 1625 if ((char)ch == '\n')
1630 break; 1626 break;
diff --git a/which.c b/which.c
index b3fd934d7..07c0e0d85 100644
--- a/which.c
+++ b/which.c
@@ -40,7 +40,7 @@ extern int which_main(int argc, char **argv)
40 if (!path_list) 40 if (!path_list)
41 path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"; 41 path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
42 42
43 path_parsed = malloc (strlen(path_list) + 1); 43 path_parsed = xmalloc (strlen(path_list) + 1);
44 strcpy (path_parsed, path_list); 44 strcpy (path_parsed, path_list);
45 45
46 /* Replace colons with zeros in path_parsed and count them */ 46 /* Replace colons with zeros in path_parsed and count them */