mirror of git://git.suckless.org/ubase
Sweep through code and replace malloc() with emalloc() etc.
This commit is contained in:
parent
550b655d98
commit
5b9ea69b08
4
dmesg.c
4
dmesg.c
|
@ -54,9 +54,7 @@ main(int argc, char *argv[])
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
eprintf("klogctl:");
|
eprintf("klogctl:");
|
||||||
|
|
||||||
buf = malloc(n);
|
buf = emalloc(n);
|
||||||
if (!buf)
|
|
||||||
eprintf("malloc:");
|
|
||||||
|
|
||||||
n = klogctl(SYSLOG_ACTION_READ_ALL, buf, n);
|
n = klogctl(SYSLOG_ACTION_READ_ALL, buf, n);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
|
|
6
insmod.c
6
insmod.c
|
@ -37,8 +37,7 @@ main(int argc, char *argv[])
|
||||||
if (fstat(fd, &sb) < 0)
|
if (fstat(fd, &sb) < 0)
|
||||||
eprintf("stat %s:", argv[0]);
|
eprintf("stat %s:", argv[0]);
|
||||||
blen = sb.st_size;
|
blen = sb.st_size;
|
||||||
if(!(buf = malloc(blen)))
|
buf = emalloc(blen);
|
||||||
eprintf("malloc:");
|
|
||||||
|
|
||||||
n = read(fd, buf, blen);
|
n = read(fd, buf, blen);
|
||||||
if(n < 0 || (size_t)n != blen)
|
if(n < 0 || (size_t)n != blen)
|
||||||
|
@ -51,8 +50,7 @@ main(int argc, char *argv[])
|
||||||
plen += strlen(argv[i]);
|
plen += strlen(argv[i]);
|
||||||
if (plen > 0) {
|
if (plen > 0) {
|
||||||
plen += argc;
|
plen += argc;
|
||||||
if(!(opts = calloc(1, plen)))
|
opts = ecalloc(1, plen);
|
||||||
eprintf("calloc:");
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
strcat(opts, argv[i]);
|
strcat(opts, argv[i]);
|
||||||
if (i + 1 < argc)
|
if (i + 1 < argc)
|
||||||
|
|
|
@ -68,9 +68,7 @@ main(int argc, char *argv[])
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
|
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
|
||||||
onode = malloc(sizeof(*onode));
|
onode = emalloc(sizeof(*onode));
|
||||||
if (!onode)
|
|
||||||
eprintf("malloc:");
|
|
||||||
onode->pid = estrtol(p, 10);
|
onode->pid = estrtol(p, 10);
|
||||||
onode->next = omithead;
|
onode->next = omithead;
|
||||||
omithead = onode;
|
omithead = onode;
|
||||||
|
|
4
mkswap.c
4
mkswap.c
|
@ -58,9 +58,7 @@ main(int argc, char *argv[])
|
||||||
if (fstat(fd, &sb) < 0)
|
if (fstat(fd, &sb) < 0)
|
||||||
eprintf("stat %s:", argv[0]);
|
eprintf("stat %s:", argv[0]);
|
||||||
|
|
||||||
buf = calloc(1, pagesize);
|
buf = ecalloc(1, pagesize);
|
||||||
if (!buf)
|
|
||||||
eprintf("malloc:");
|
|
||||||
|
|
||||||
pages = sb.st_size / pagesize;
|
pages = sb.st_size / pagesize;
|
||||||
if (pages < SWAP_MIN_PAGES)
|
if (pages < SWAP_MIN_PAGES)
|
||||||
|
|
4
pidof.c
4
pidof.c
|
@ -49,9 +49,7 @@ main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
|
for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
|
||||||
onode = malloc(sizeof(*onode));
|
onode = emalloc(sizeof(*onode));
|
||||||
if (!onode)
|
|
||||||
eprintf("malloc:");
|
|
||||||
if (strcmp(p, "%PPID") == 0)
|
if (strcmp(p, "%PPID") == 0)
|
||||||
onode->pid = getppid();
|
onode->pid = getppid();
|
||||||
else
|
else
|
||||||
|
|
4
su.c
4
su.c
|
@ -151,9 +151,7 @@ msetenv(const char *name, const char *value)
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
sz = strlen(name) + strlen(value) + 2;
|
sz = strlen(name) + strlen(value) + 2;
|
||||||
buf = malloc(sz);
|
buf = emalloc(sz);
|
||||||
if (!buf)
|
|
||||||
eprintf("malloc:");
|
|
||||||
snprintf(buf, sz, "%s=%s", name, value);
|
snprintf(buf, sz, "%s=%s", name, value);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
8
umount.c
8
umount.c
|
@ -70,12 +70,8 @@ umountall(int flags)
|
||||||
while ((me = getmntent(fp))) {
|
while ((me = getmntent(fp))) {
|
||||||
if (strcmp(me->mnt_type, "proc") == 0)
|
if (strcmp(me->mnt_type, "proc") == 0)
|
||||||
continue;
|
continue;
|
||||||
mntdirs = realloc(mntdirs, ++len * sizeof(*mntdirs));
|
mntdirs = erealloc(mntdirs, ++len * sizeof(*mntdirs));
|
||||||
if (!mntdirs)
|
mntdirs[len - 1] = estrdup(me->mnt_dir);
|
||||||
eprintf("realloc:");
|
|
||||||
mntdirs[len - 1] = strdup(me->mnt_dir);
|
|
||||||
if (!mntdirs[len - 1])
|
|
||||||
eprintf("strdup:");
|
|
||||||
}
|
}
|
||||||
endmntent(fp);
|
endmntent(fp);
|
||||||
while (--len >= 0) {
|
while (--len >= 0) {
|
||||||
|
|
|
@ -19,7 +19,5 @@ apathmax(char **p, long *size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(*p = malloc(*size)))
|
*p = emalloc(*size);
|
||||||
eprintf("malloc:");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,7 @@ ttytostr(int tty_maj, int tty_min)
|
||||||
|
|
||||||
/* Up to 10k ttys */
|
/* Up to 10k ttys */
|
||||||
len = strlen(pts) + 4 + 1;
|
len = strlen(pts) + 4 + 1;
|
||||||
ttystr = malloc(len);
|
ttystr = emalloc(len);
|
||||||
if (!ttystr)
|
|
||||||
eprintf("malloc:");
|
|
||||||
switch (tty_maj) {
|
switch (tty_maj) {
|
||||||
case 136:
|
case 136:
|
||||||
snprintf(ttystr, len, "%s%d", pts, tty_min);
|
snprintf(ttystr, len, "%s%d", pts, tty_min);
|
||||||
|
|
Loading…
Reference in New Issue