summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorMatt Kraai2000-09-13 02:46:14 +0000
committerMatt Kraai2000-09-13 02:46:14 +0000
commit322ae93a5e0b78b65831f9fd87fd456eb84d21a1 (patch)
tree5b967e1d873ff6eff8296bf9fda73825f0c55884 /coreutils
parentb89075298edf0a471b9046b1f3c8a936e18ead20 (diff)
downloadbusybox-322ae93a5e0b78b65831f9fd87fd456eb84d21a1.zip
busybox-322ae93a5e0b78b65831f9fd87fd456eb84d21a1.tar.gz
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.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/ln.c2
-rw-r--r--coreutils/sort.c12
-rw-r--r--coreutils/tail.c12
-rw-r--r--coreutils/test.c4
4 files changed, 11 insertions, 19 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 8b8fa1c..d5f44ea 100644
--- a/coreutils/ln.c
+++ b/coreutils/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, "/");
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 6af5c4d..a74f96a 100644
--- a/coreutils/sort.c
+++ b/coreutils/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/coreutils/tail.c b/coreutils/tail.c
index c940bfe..dcb4f67 100644
--- a/coreutils/tail.c
+++ b/coreutils/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/coreutils/test.c b/coreutils/test.c
index 6dde718..a2bec44 100644
--- a/coreutils/test.c
+++ b/coreutils/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);
}