Introduction
Introduction Statistics Contact Development Disclaimer Help
use calloc instead of gmallocz - geomyidae - A small C-based gopherd.
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit 2361134beb5458adbff043ea611884a090d56d42
parent b002d13b34f69f0efc797b252f9db0878262581d
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 11 Jun 2017 19:51:55 +0200
use calloc instead of gmallocz
gmallocz always called with a non-zero argument so it was cleared using memset.
Diffstat:
M ind.c | 34 ++++++++++++++++-------------…
M ind.h | 2 +-
M main.c | 2 +-
3 files changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/ind.c b/ind.c
@@ -39,6 +39,19 @@ filetype type[] = {
};
void *
+xcalloc(size_t nmemb, size_t size)
+{
+ void *p;
+
+ if (!(p = calloc(nmemb, size))) {
+ perror("calloc");
+ exit(1);
+ }
+
+ return p;
+}
+
+void *
xmalloc(size_t size)
{
void *p;
@@ -93,19 +106,6 @@ gettype(char *filename)
return &type[0];
}
-void *
-gmallocz(int l, int d)
-{
- char *ret;
-
- ret = xmalloc(l);
-
- if(d)
- memset(ret, 0, l);
-
- return (void *)ret;
-}
-
char *
readln(int fd)
{
@@ -168,7 +168,7 @@ addelem(Elems *e, char *s)
e->num++;
e->e = xrealloc(e->e, sizeof(char *) * e->num);
- e->e[e->num - 1] = gmallocz(slen, 2);
+ e->e[e->num - 1] = xcalloc(1, slen);
strncpy(e->e[e->num - 1], s, slen - 1);
return;
@@ -180,7 +180,7 @@ getadv(char *str)
char *b, *e;
Elems *ret;
- ret = gmallocz(sizeof(Elems), 2);
+ ret = xcalloc(1, sizeof(Elems));
if(*str != '[') {
b = str;
if(*str == 't')
@@ -238,7 +238,7 @@ scanfile(char *fname)
if(fd < 0)
return nil;
- ret = gmallocz(sizeof(Indexs), 2);
+ ret = xcalloc(1, sizeof(Indexs));
while((ln = readln(fd)) != nil) {
el = getadv(ln);
@@ -307,7 +307,7 @@ smprintf(char *fmt, ...)
size = vsnprintf(NULL, 0, fmt, fmtargs);
va_end(fmtargs);
- ret = gmallocz(++size, 2);
+ ret = xcalloc(1, ++size);
va_start(fmtargs, fmt);
vsnprintf(ret, size, fmt, fmtargs);
va_end(fmtargs);
diff --git a/ind.h b/ind.h
@@ -31,7 +31,7 @@ struct filetype {
};
filetype *gettype(char *filename);
-void *gmallocz(int l, int d);
+void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *xstrdup(const char *str);
diff --git a/main.c b/main.c
@@ -374,7 +374,7 @@ main(int argc, char *argv[])
} ARGEND;
if(ohost == nil) {
- ohost = gmallocz(513, 2);
+ ohost = xcalloc(1, 513);
if(gethostname(ohost, 512) < 0) {
perror("gethostname");
free(ohost);
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.