aboutsummaryrefslogtreecommitdiff
path: root/coreutils
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 /coreutils
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.
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 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