[hackers] [ubase] Sweep through code and replace malloc() with emalloc() etc. || sin
commit 5b9ea69b08a15dcad0ce2422289d86d459502197
Author: sin <sin_AT_2f30.org>
Date: Wed Apr 30 13:08:16 2014 +0100
Sweep through code and replace malloc() with emalloc() etc.
diff --git a/dmesg.c b/dmesg.c
index a4c5b43..c60c503 100644
--- a/dmesg.c
+++ b/dmesg.c
_AT_@ -54,9 +54,7 @@ main(int argc, char *argv[])
if (n < 0)
eprintf("klogctl:");
- buf = malloc(n);
- if (!buf)
- eprintf("malloc:");
+ buf = emalloc(n);
n = klogctl(SYSLOG_ACTION_READ_ALL, buf, n);
if (n < 0)
diff --git a/insmod.c b/insmod.c
index 0ca23dc..c6ef908 100644
--- a/insmod.c
+++ b/insmod.c
_AT_@ -37,8 +37,7 @@ main(int argc, char *argv[])
if (fstat(fd, &sb) < 0)
eprintf("stat %s:", argv[0]);
blen = sb.st_size;
- if(!(buf = malloc(blen)))
- eprintf("malloc:");
+ buf = emalloc(blen);
n = read(fd, buf, blen);
if(n < 0 || (size_t)n != blen)
_AT_@ -51,8 +50,7 @@ main(int argc, char *argv[])
plen += strlen(argv[i]);
if (plen > 0) {
plen += argc;
- if(!(opts = calloc(1, plen)))
- eprintf("calloc:");
+ opts = ecalloc(1, plen);
for (i = 0; i < argc; i++) {
strcat(opts, argv[i]);
if (i + 1 < argc)
diff --git a/killall5.c b/killall5.c
index 8862210..0d7d02d 100644
--- a/killall5.c
+++ b/killall5.c
_AT_@ -68,9 +68,7 @@ main(int argc, char *argv[])
} ARGEND;
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
- onode = malloc(sizeof(*onode));
- if (!onode)
- eprintf("malloc:");
+ onode = emalloc(sizeof(*onode));
onode->pid = estrtol(p, 10);
onode->next = omithead;
omithead = onode;
diff --git a/mkswap.c b/mkswap.c
index deba3ff..25ef31c 100644
--- a/mkswap.c
+++ b/mkswap.c
_AT_@ -58,9 +58,7 @@ main(int argc, char *argv[])
if (fstat(fd, &sb) < 0)
eprintf("stat %s:", argv[0]);
- buf = calloc(1, pagesize);
- if (!buf)
- eprintf("malloc:");
+ buf = ecalloc(1, pagesize);
pages = sb.st_size / pagesize;
if (pages < SWAP_MIN_PAGES)
diff --git a/pidof.c b/pidof.c
index f91ad10..1f35558 100644
--- a/pidof.c
+++ b/pidof.c
_AT_@ -49,9 +49,7 @@ main(int argc, char *argv[])
return 1;
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
- onode = malloc(sizeof(*onode));
- if (!onode)
- eprintf("malloc:");
+ onode = emalloc(sizeof(*onode));
if (strcmp(p, "%PPID") == 0)
onode->pid = getppid();
else
diff --git a/su.c b/su.c
index d51b1ae..c93d9c8 100644
--- a/su.c
+++ b/su.c
_AT_@ -151,9 +151,7 @@ msetenv(const char *name, const char *value)
size_t sz;
sz = strlen(name) + strlen(value) + 2;
- buf = malloc(sz);
- if (!buf)
- eprintf("malloc:");
+ buf = emalloc(sz);
snprintf(buf, sz, "%s=%s", name, value);
return buf;
}
diff --git a/umount.c b/umount.c
index 485417c..44b0c1f 100644
--- a/umount.c
+++ b/umount.c
_AT_@ -70,12 +70,8 @@ umountall(int flags)
while ((me = getmntent(fp))) {
if (strcmp(me->mnt_type, "proc") == 0)
continue;
- mntdirs = realloc(mntdirs, ++len * sizeof(*mntdirs));
- if (!mntdirs)
- eprintf("realloc:");
- mntdirs[len - 1] = strdup(me->mnt_dir);
- if (!mntdirs[len - 1])
- eprintf("strdup:");
+ mntdirs = erealloc(mntdirs, ++len * sizeof(*mntdirs));
+ mntdirs[len - 1] = estrdup(me->mnt_dir);
}
endmntent(fp);
while (--len >= 0) {
diff --git a/util/apathmax.c b/util/apathmax.c
index 5dc831f..ed53bf3 100644
--- a/util/apathmax.c
+++ b/util/apathmax.c
_AT_@ -19,7 +19,5 @@ apathmax(char **p, long *size)
}
}
- if(!(*p = malloc(*size)))
- eprintf("malloc:");
+ *p = emalloc(*size);
}
-
diff --git a/util/tty.c b/util/tty.c
index 2a70c65..5769620 100644
--- a/util/tty.c
+++ b/util/tty.c
_AT_@ -21,9 +21,7 @@ ttytostr(int tty_maj, int tty_min)
/* Up to 10k ttys */
len = strlen(pts) + 4 + 1;
- ttystr = malloc(len);
- if (!ttystr)
- eprintf("malloc:");
+ ttystr = emalloc(len);
switch (tty_maj) {
case 136:
snprintf(ttystr, len, "%s%d", pts, tty_min);
Received on Wed Apr 30 2014 - 14:12:21 CEST
This archive was generated by hypermail 2.3.0
: Wed Apr 30 2014 - 14:24:12 CEST