From 10eff860a28b96582526eb739fd0a55441669938 Mon Sep 17 00:00:00 2001 From: "m@mmmmarascio.xyz" Date: Mon, 14 Mar 2016 09:29:35 -0700 Subject: [PATCH] Replace mh_xmalloc() with mh_xcalloc() calloc() is safer, because it initialize the memory to zero. --- h/utils.h | 1 - sbr/brkstring.c | 2 +- sbr/concat.c | 2 +- sbr/context_replace.c | 4 ++-- sbr/crawl_folders.c | 4 ++-- sbr/encode_rfc2047.c | 4 ++-- sbr/fmt_addr.c | 2 +- sbr/fmt_new.c | 4 ++-- sbr/fmt_rfc2047.c | 2 +- sbr/folder_read.c | 6 +++--- sbr/folder_realloc.c | 2 +- sbr/getarguments.c | 2 +- sbr/getcpy.c | 4 ++-- sbr/lock_file.c | 4 ++-- sbr/m_getfld.c | 2 +- sbr/mf.c | 2 +- sbr/putenv.c | 4 ++-- sbr/readconfig.c | 2 +- sbr/seq_list.c | 2 +- sbr/utils.c | 22 +--------------------- sbr/vfgets.c | 2 +- uip/aliasbr.c | 6 +++--- uip/anno.c | 4 ++-- uip/flist.c | 8 +++----- uip/folder.c | 2 +- uip/forw.c | 2 +- uip/mhl.c | 2 +- uip/mhparse.c | 4 ++-- uip/new.c | 6 +++--- uip/rcvdist.c | 4 ++-- uip/repl.c | 6 +++--- uip/rmm.c | 2 +- uip/scansbr.c | 6 +++--- uip/send.c | 4 ++-- uip/sortm.c | 6 ++---- uip/spost.c | 2 +- 36 files changed, 59 insertions(+), 84 deletions(-) diff --git a/h/utils.h b/h/utils.h index 6f74c32..35d0833 100644 --- a/h/utils.h +++ b/h/utils.h @@ -2,7 +2,6 @@ ** utils.h -- utility prototypes */ -void *mh_xmalloc(size_t); void *mh_xrealloc(void *, size_t); void *mh_xcalloc(size_t, size_t); char *pwd(void); diff --git a/sbr/brkstring.c b/sbr/brkstring.c index 205c8c9..acbba6a 100644 --- a/sbr/brkstring.c +++ b/sbr/brkstring.c @@ -30,7 +30,7 @@ brkstring(char *str, char *brksep, char *brkterm) /* allocate initial space for pointers on first call */ if (!broken) { len = NUMBROKEN; - broken = (char **)mh_xmalloc((size_t)(len * sizeof(*broken))); + broken = (char **)mh_xcalloc((size_t)len, sizeof(*broken)); } /* diff --git a/sbr/concat.c b/sbr/concat.c index 4a57656..9efe731 100644 --- a/sbr/concat.c +++ b/sbr/concat.c @@ -36,7 +36,7 @@ concat(char *s1, ...) len += strlen(cp); va_end(list); - dp = sp = mh_xmalloc(len); + dp = sp = mh_xcalloc(len, sizeof(char)); sp = copy(s1, sp); diff --git a/sbr/context_replace.c b/sbr/context_replace.c index dd6e631..2c3bc18 100644 --- a/sbr/context_replace.c +++ b/sbr/context_replace.c @@ -19,7 +19,7 @@ context_replace(char *key, char *value) ** If list is emtpy, allocate head of profile/context list. */ if (!m_defs) { - m_defs = (struct node *) mh_xmalloc(sizeof(*np)); + m_defs = (struct node *) mh_xcalloc(1, sizeof(*np)); np = m_defs; np->n_name = getcpy(key); @@ -53,7 +53,7 @@ context_replace(char *key, char *value) /* ** Else add this new entry at the end */ - np->n_next = (struct node *) mh_xmalloc(sizeof(*np)); + np->n_next = (struct node *) mh_xcalloc(1, sizeof(*np)); np = np->n_next; np->n_name = getcpy(key); diff --git a/sbr/crawl_folders.c b/sbr/crawl_folders.c index 47327ed..2e1a094 100644 --- a/sbr/crawl_folders.c +++ b/sbr/crawl_folders.c @@ -142,10 +142,10 @@ crawl_folders_body(struct crawl_context *crawl, char *dir, void crawl_folders(char *dir, crawl_callback_t *callback, void *baton) { - struct crawl_context *crawl = mh_xmalloc(sizeof(*crawl)); + struct crawl_context *crawl = mh_xcalloc(1, sizeof(*crawl)); crawl->max = CRAWL_NUMFOLDERS; crawl->total = crawl->start = crawl->foldp = 0; - crawl->folders = mh_xmalloc(crawl->max * sizeof(*crawl->folders)); + crawl->folders = mh_xcalloc(crawl->max, sizeof(*crawl->folders)); crawl_folders_body(crawl, dir, callback, baton); diff --git a/sbr/encode_rfc2047.c b/sbr/encode_rfc2047.c index 852c261..844f0c4 100644 --- a/sbr/encode_rfc2047.c +++ b/sbr/encode_rfc2047.c @@ -204,7 +204,7 @@ field_encode_quoted(const char *name, char **value, const char *charset, ** least one) until we get to the actual ** text. Copy until we get to a non-space. */ - output = mh_xmalloc(outlen); + output = mh_xcalloc(outlen, sizeof(char)); q = output; while (is_fws(*p)) { *q++ = *p++; @@ -340,7 +340,7 @@ utf8len(const char *p) static void unfold_header(char **value, int len) { - char *str = mh_xmalloc(len + 1); + char *str = mh_xcalloc(len + 1, sizeof(char)); char *p = str, *q = *value; while (*q != '\0') { diff --git a/sbr/fmt_addr.c b/sbr/fmt_addr.c index c7379b1..c89a195 100644 --- a/sbr/fmt_addr.c +++ b/sbr/fmt_addr.c @@ -60,7 +60,7 @@ formataddr(char *orig, char *str) /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { - buf = mh_xmalloc(BUFINCR); + buf = mh_xcalloc(BUFINCR, sizeof(char)); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; diff --git a/sbr/fmt_new.c b/sbr/fmt_new.c index 9a7988e..c3b1ea2 100644 --- a/sbr/fmt_new.c +++ b/sbr/fmt_new.c @@ -43,7 +43,7 @@ new_fs(char *form, char *def_form) if (fstat(fileno(fp), &st) == -1) { adios(EX_IOERR, form, "unable to stat format file"); } - formats = mh_xmalloc((size_t) st.st_size + 1); + formats = mh_xcalloc((size_t) st.st_size + 1, sizeof(char)); if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) { adios(EX_IOERR, form, "error reading format file"); } @@ -60,7 +60,7 @@ new_fs(char *form, char *def_form) if (fstat(fileno(fp), &st) == -1) { adios(EX_IOERR, def_form, "unable to stat format file"); } - formats = mh_xmalloc((size_t) st.st_size + 1); + formats = mh_xcalloc((size_t) st.st_size + 1, sizeof(char)); if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) { adios(EX_IOERR, def_form, "error reading format file"); } diff --git a/sbr/fmt_rfc2047.c b/sbr/fmt_rfc2047.c index faa3cc2..e9db55e 100644 --- a/sbr/fmt_rfc2047.c +++ b/sbr/fmt_rfc2047.c @@ -209,7 +209,7 @@ decode_rfc2047(char *str, char *dst, size_t dstlen) if (use_iconv) { saveq = q; savedstlen = dstlen; - q = convbuf = (char *) mh_xmalloc(endofmime - startofmime); + q = convbuf = (char *) mh_xcalloc(endofmime - startofmime, sizeof(char)); } /* ** ADDCHR2 is for adding characters when q is or might be convbuf: diff --git a/sbr/folder_read.c b/sbr/folder_read.c index ec51d64..67775f1 100644 --- a/sbr/folder_read.c +++ b/sbr/folder_read.c @@ -46,7 +46,7 @@ folder_read(char *name) } /* Allocate the main structure for folder information */ - mp = (struct msgs *) mh_xmalloc((size_t) sizeof(*mp)); + mp = (struct msgs *) mh_xcalloc(1, (size_t) sizeof(*mp)); clear_folder_flags(mp); mp->foldpath = name; @@ -66,7 +66,7 @@ folder_read(char *name) ** name of the messages in this folder. */ len = NUMMSGS; - mi = (int *) mh_xmalloc((size_t) (len * sizeof(*mi))); + mi = (int *) mh_xcalloc((size_t) len, sizeof(*mi)); while ((dp = readdir(dd))) { if ((msgnum = m_atoi(dp->d_name)) && msgnum > 0) { @@ -128,7 +128,7 @@ folder_read(char *name) /* Allocate space for status of each message. */ - mp->msgstats = mh_xmalloc(MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)); + mp->msgstats = mh_xcalloc(MSGSTATSIZE(mp, mp->lowoff, mp->hghoff), 1); /* ** Clear all the flag bits for all the message diff --git a/sbr/folder_realloc.c b/sbr/folder_realloc.c index 47b9281..bfdc44f 100644 --- a/sbr/folder_realloc.c +++ b/sbr/folder_realloc.c @@ -54,7 +54,7 @@ folder_realloc(struct msgs *mp, int lo, int hi) seqset_t *tmpstats; /* first allocate the new message status space */ - tmpstats = mh_xmalloc(MSGSTATSIZE(mp, lo, hi)); + tmpstats = mh_xcalloc(MSGSTATSIZE(mp, lo, hi), 1); /* then copy messages status array with shift */ if (mp->nummsg > 0) { diff --git a/sbr/getarguments.c b/sbr/getarguments.c index 14c9a23..a700443 100644 --- a/sbr/getarguments.c +++ b/sbr/getarguments.c @@ -28,7 +28,7 @@ getarguments(char *invo_name, int argc, char **argv, int check_context) n++; } - arguments = (char **) mh_xmalloc((argc + n) * sizeof(*arguments)); + arguments = (char **) mh_xcalloc(argc + n, sizeof(*arguments)); bp = arguments; /* Copy any arguments from profile/context */ diff --git a/sbr/getcpy.c b/sbr/getcpy.c index 478986a..77564a1 100644 --- a/sbr/getcpy.c +++ b/sbr/getcpy.c @@ -22,10 +22,10 @@ getcpy(char *str) if (str) { len = strlen(str) + 1; - cp = mh_xmalloc(len); + cp = mh_xcalloc(len, sizeof(char)); memcpy(cp, str, len); } else { - cp = mh_xmalloc((size_t) 1); + cp = mh_xcalloc((size_t) 1, sizeof(char)); *cp = '\0'; } return cp; diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 7309c86..3aa0030 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -516,11 +516,11 @@ timerON(char *curlock, int fd) struct lock *lp; size_t len; - lp = (struct lock *) mh_xmalloc(sizeof(*lp)); + lp = (struct lock *) mh_xcalloc(1, sizeof(*lp)); len = strlen(curlock) + 1; lp->l_fd = fd; - lp->l_lock = mh_xmalloc(len); + lp->l_lock = mh_xcalloc(len, sizeof(char)); memcpy(lp->l_lock, curlock, len); lp->l_next = l_top; diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 826cfb3..6931b2e 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -609,7 +609,7 @@ thisisanmbox(FILE *iob) continue; } c = strlen(delimstr); - fdelim = (unsigned char *) mh_xmalloc((size_t) (c + 3)); + fdelim = (unsigned char *) mh_xcalloc((size_t) (c + 3), sizeof(char)); *fdelim++ = '\0'; *fdelim = '\n'; msg_delim = (char *)fdelim+1; diff --git a/sbr/mf.c b/sbr/mf.c index 633522b..3134328 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -42,7 +42,7 @@ getcpy(char *s) for(;;) pause(); } - p = mh_xmalloc((size_t) (strlen(s) + 2)); + p = mh_xcalloc((size_t) (strlen(s) + 2), sizeof(char)); strcpy(p, s); return p; } diff --git a/sbr/putenv.c b/sbr/putenv.c index a2ec7d3..54c4068 100644 --- a/sbr/putenv.c +++ b/sbr/putenv.c @@ -25,7 +25,7 @@ m_putenv(char *name, char *value) int i; char **ep, **nep, *cp; - cp = mh_xmalloc((size_t) (strlen(name) + strlen(value) + 2)); + cp = mh_xcalloc((size_t) (strlen(name) + strlen(value) + 2), sizeof(char)); sprintf(cp, "%s=%s", name, value); @@ -35,7 +35,7 @@ m_putenv(char *name, char *value) return 0; } - nep = (char **) mh_xmalloc((size_t) ((i + 2) * sizeof(*nep))); + nep = (char **) mh_xcalloc((size_t) (i + 2), sizeof(*nep)); for (ep = environ, i = 0; *ep; nep[i++] = *ep++) continue; diff --git a/sbr/readconfig.c b/sbr/readconfig.c index bc9329f..747aede 100644 --- a/sbr/readconfig.c +++ b/sbr/readconfig.c @@ -52,7 +52,7 @@ readconfig(struct node **npp, FILE *ib, char *file, int ctx) ib)) { case FLD: case FLDPLUS: - np = (struct node *) mh_xmalloc(sizeof(*np)); + np = (struct node *) mh_xcalloc(1, sizeof(*np)); *npp = np; *(npp = &np->n_next) = NULL; np->n_name = getcpy(name); diff --git a/sbr/seq_list.c b/sbr/seq_list.c index 148ecb9..241c720 100644 --- a/sbr/seq_list.c +++ b/sbr/seq_list.c @@ -27,7 +27,7 @@ seq_list(struct msgs *mp, char *seqname) /* On first invocation, allocate initial buffer space */ if (!buffer) { len = MAXBUFFER; - buffer = mh_xmalloc((size_t) len); + buffer = mh_xcalloc((size_t) len, sizeof(char)); } /* diff --git a/sbr/utils.c b/sbr/utils.c index fa4cfdb..f964e7e 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -22,26 +22,6 @@ #define MAXMSGS 256 /* -** Safely call malloc -*/ -void * -mh_xmalloc(size_t size) -{ - void *memory; - - if (size == 0) { - adios(EX_SOFTWARE, NULL, "Tried to malloc 0 bytes"); - } - - memory = malloc(size); - if (!memory) { - adios(EX_OSERR, NULL, "Malloc failed"); - } - - return memory; -} - -/* ** Safely call realloc */ void * @@ -134,7 +114,7 @@ add(char *s2, char *s1) len2 = strlen(s2); } - cp = mh_xmalloc(len1 + len2 + 1); + cp = mh_xcalloc(len1 + len2 + 1, sizeof(char)); /* Copy s1 and free it */ if (s1) { diff --git a/sbr/vfgets.c b/sbr/vfgets.c index 3e71ad0..1718ff1 100644 --- a/sbr/vfgets.c +++ b/sbr/vfgets.c @@ -22,7 +22,7 @@ vfgets(FILE *in, char **bp) static char *pp = NULL; if (pp == NULL) - pp = mh_xmalloc((size_t) (len = BUFSIZ)); + pp = mh_xcalloc((size_t) (len = BUFSIZ), sizeof(char)); for (ep = (cp = pp) + len - 1;;) { if (fgets(cp, ep - cp + 1, in) == NULL) { diff --git a/uip/aliasbr.c b/uip/aliasbr.c index bda7326..744d3bf 100644 --- a/uip/aliasbr.c +++ b/uip/aliasbr.c @@ -431,7 +431,7 @@ add_aka(struct aka *ak, char *pp) if (strcmp(pp, ad->ad_text)==0) return; - ad = (struct adr *) mh_xmalloc(sizeof(*ad)); + ad = (struct adr *) mh_xcalloc(1, sizeof(*ad)); ad->ad_text = getcpy(pp); ad->ad_local = strchr(pp, '@') == NULL; ad->ad_next = NULL; @@ -468,7 +468,7 @@ akalloc(char *id) { struct aka *p; - p = (struct aka *) mh_xmalloc(sizeof(*p)); + p = (struct aka *) mh_xcalloc(1, sizeof(*p)); p->ak_name = getcpy(id); p->ak_visible = 0; @@ -489,7 +489,7 @@ hmalloc(struct passwd *pw) { struct home *p; - p = (struct home *) mh_xmalloc(sizeof(*p)); + p = (struct home *) mh_xcalloc(1, sizeof(*p)); p->h_name = getcpy(pw->pw_name); p->h_uid = pw->pw_uid; diff --git a/uip/anno.c b/uip/anno.c index 1c97179..96b896c 100644 --- a/uip/anno.c +++ b/uip/anno.c @@ -305,7 +305,7 @@ annolist(char *file, unsigned char *comp, int number) } /* We'll grow this buffer as needed. */ - field = (char *)mh_xmalloc(field_size = 256); + field = (char *)mh_xcalloc(field_size = 256, sizeof(char)); make_comp(&comp); length = strlen(comp); /* Convenience copy. */ @@ -459,7 +459,7 @@ dodel(int fd, unsigned char *comp, char *text, FILE *tmp, int number) if ((fp = fdopen(fd, "r")) == NULL) { adios(EX_IOERR, NULL, "unable to fdopen file."); } - field = (char *)mh_xmalloc(field_size); + field = (char *)mh_xcalloc(field_size, sizeof(char)); /* ** Copy lines from the input file to the temporary file diff --git a/uip/flist.c b/uip/flist.c index 68acabb..d2433a2 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -143,8 +143,7 @@ main(int argc, char **argv) /* allocate the initial space to record the folder names */ numfolders = 0; maxfolders = MAXFOLDERS; - foldersToDo = (char **) mh_xmalloc((size_t) - (maxfolders * sizeof(*foldersToDo))); + foldersToDo = (char **) mh_xcalloc((size_t) maxfolders, sizeof(*foldersToDo)); /* no sequences yet */ numsequences = 0; @@ -295,7 +294,7 @@ GetFolderOrder(void) AllocFolders(&orders, &nOrdersAlloced, nOrders + 1); o = &orders[nOrders++]; o->priority = priority++; - o->name = (char *) mh_xmalloc(p - s + 1); + o->name = (char *) mh_xcalloc(p - s + 1, sizeof(char)); strncpy(o->name, s, p - s); o->name[p - s] = 0; } else @@ -624,8 +623,7 @@ AllocFolders(struct Folder **f, int *nfa, int n) return; if (*f == NULL) { *nfa = 10; - *f = (struct Folder *) mh_xmalloc( - *nfa * (sizeof(struct Folder))); + *f = (struct Folder *) mh_xcalloc(*nfa, sizeof(struct Folder)); } else { *nfa *= 2; *f = (struct Folder *) mh_xrealloc( diff --git a/uip/folder.c b/uip/folder.c index 4ffb9f5..b4758cf 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -324,7 +324,7 @@ main(int argc, char **argv) /* Allocate initial space to record folder information */ maxFolderInfo = CRAWL_NUMFOLDERS; - fi = mh_xmalloc(maxFolderInfo * sizeof(*fi)); + fi = mh_xcalloc(maxFolderInfo, sizeof(*fi)); /* ** Scan the folders diff --git a/uip/forw.c b/uip/forw.c index 4bb03d3..77339b3 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -333,7 +333,7 @@ build_form(char *form, char *digest, int volume, int issue) if ((in = dup(fileno(tmp))) == NOTOK) adios(EX_OSERR, "dup", "unable to"); - line = mh_xmalloc((unsigned) fmtsize); + line = mh_xcalloc((unsigned) fmtsize, sizeof(char)); fmt_scan(fmt, line, fmtsize, dat); fputs(line, tmp); free(line); diff --git a/uip/mhl.c b/uip/mhl.c index 6989c70..15489ff 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -674,7 +674,7 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec) continue; } if (dobody && !mh_strcasecmp(c1->c_name, "body")) { - holder.c_text = mh_xmalloc(sizeof(buf)); + holder.c_text = mh_xcalloc(sizeof(buf), sizeof(char)); strncpy(holder.c_text, buf, sizeof(buf)); while (state == BODY) { putcomp(c1, &holder, BODYCOMP); diff --git a/uip/mhparse.c b/uip/mhparse.c index b7b8694..3522a97 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -475,7 +475,7 @@ add_header(CT ct, char *name, char *value) HF hp; /* allocate header field structure */ - hp = mh_xmalloc(sizeof(*hp)); + hp = mh_xcalloc(1, sizeof(*hp)); /* link data into header structure */ hp->name = name; @@ -577,7 +577,7 @@ extract_name_value(char *name_suffix, char *value) { for (; *cp != '"'; ++cp) ; - extracted_name_value = mh_xmalloc(cp - name_suffix_begin + 1); + extracted_name_value = mh_xcalloc(cp - name_suffix_begin + 1, sizeof(char)); memcpy(extracted_name_value, name_suffix_begin, cp - name_suffix_begin); extracted_name_value[cp - name_suffix_begin] = '\0'; diff --git a/uip/new.c b/uip/new.c index cb16dea..9774729 100644 --- a/uip/new.c +++ b/uip/new.c @@ -187,9 +187,9 @@ check_folder(char *folder, size_t len, struct list_state *b) if (is_cur || msgnums != NULL) { if (*b->first == NULL) { - *b->first = b->node = mh_xmalloc(sizeof(*b->node)); + *b->first = b->node = mh_xcalloc(1, sizeof(*b->node)); } else { - b->node->n_next = mh_xmalloc(sizeof(*b->node)); + b->node->n_next = mh_xcalloc(1, sizeof(*b->node)); b->node = b->node->n_next; } b->node->n_name = folder; @@ -280,7 +280,7 @@ join_sequences(char *sequences[]) for (i = 0; sequences[i] != NULL; i++) { len += strlen(sequences[i]) + 1; } - result = mh_xmalloc(len + 1); + result = mh_xcalloc(len + 1, sizeof(char)); for (i = 0, cp = result; sequences[i] != NULL; i++, cp += len + 1) { len = strlen(sequences[i]); diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 53cc0f0..deeccb8 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -179,7 +179,7 @@ rcvdistout(FILE *inb, char *form, char *addrs) *--savecomp = 0; for (i = ncomps; i--;) { - *nxtbuf++ = mh_xmalloc(SBUFSIZ); + *nxtbuf++ = mh_xcalloc(SBUFSIZ, sizeof(char)); } nxtbuf = compbuffers; tmpbuf = *nxtbuf++; @@ -252,7 +252,7 @@ rcvdistout(FILE *inb, char *form, char *addrs) finished: ; i = format_len + char_read + 256; - scanl = mh_xmalloc((size_t) i + 2); + scanl = mh_xcalloc((size_t) i + 2, sizeof(char)); dat[0] = dat[1] = dat[2] = dat[4] = 0; dat[3] = OUTPUTLINELEN; fmt_scan(fmt, scanl, i, dat); diff --git a/uip/repl.c b/uip/repl.c index f1e4bcc..fa1a7b4 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -420,7 +420,7 @@ replout(FILE *inb, char *drft, struct msgs *mp, *--savecomp = NULL; /* point at zero'd end minus 1 */ for (i = ncomps; i--; ) - *nxtbuf++ = mh_xmalloc(SBUFSIZ); + *nxtbuf++ = mh_xcalloc(SBUFSIZ, sizeof(char)); nxtbuf = compbuffers; /* point at start */ tmpbuf = *nxtbuf++; @@ -543,7 +543,7 @@ finished: } } i = format_len + char_read + 256; - scanl = mh_xmalloc((size_t) i + 2); + scanl = mh_xcalloc((size_t) i + 2, sizeof(char)); dat[0] = 0; dat[1] = 0; dat[2] = 0; @@ -646,7 +646,7 @@ formataddr(char *orig, char *str) /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { - buf = mh_xmalloc(BUFINCR); + buf = mh_xcalloc(BUFINCR, sizeof(char)); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; diff --git a/uip/rmm.c b/uip/rmm.c index f99dcbc..896497f 100644 --- a/uip/rmm.c +++ b/uip/rmm.c @@ -131,7 +131,7 @@ main(int argc, char **argv) adios(EX_SOFTWARE, NULL, "more than %d messages for refile exec", MAXARGS - 6); } - vec = (char **)mh_xmalloc((size_t)(msgs.size + 6) * sizeof(*vec)); + vec = (char **)mh_xcalloc((size_t)(msgs.size + 6), sizeof(*vec)); vec[vecp++] = "refile"; vec[vecp++] = "-src"; vec[vecp++] = concat("+", folder, NULL); diff --git a/uip/scansbr.c b/uip/scansbr.c index d985a5c..ed163f3 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -88,8 +88,8 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, width = MAXSCANL; } dat[3] = slwidth = width; - scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH * - (slwidth + 2)); /* probably for \n and \0 */ + scanl = (char *) mh_xcalloc((size_t)(slwidth + 2), + SCAN_CHARWIDTH); /* probably for \n and \0 */ /* Compile format string */ ncomps = fmt_compile(fmtstr, &fmt) + 1; FINDCOMP(datecomp, "date"); @@ -107,7 +107,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, *used_buf = NULL; /* allocate space for the items */ for (i = ncomps; i--; ) - *nxtbuf++ = mh_xmalloc(SBUFSIZ); + *nxtbuf++ = mh_xcalloc(SBUFSIZ, sizeof(char)); } /* diff --git a/uip/send.c b/uip/send.c index df81340..d47ba8e 100644 --- a/uip/send.c +++ b/uip/send.c @@ -348,7 +348,7 @@ attach(char *draft_file_name) } /* We'll grow the buffer as needed. */ - field = (char *)mh_xmalloc(field_size = 256); + field = (char *)mh_xcalloc(field_size = 256, sizeof(char)); /* ** Scan the draft file for an attachment header field name. @@ -484,7 +484,7 @@ signandenc(char *draft_file_name) } /* We'll grow the buffer as needed. */ - field = (char *)mh_xmalloc(field_size = 256); + field = (char *)mh_xcalloc(field_size = 256, sizeof(char)); /* Scan the draft file for an attachment header field name. */ while (get_line() != EOF && *field != '\0' && *field != '-') { diff --git a/uip/sortm.c b/uip/sortm.c index 5d15ed6..06ec0ca 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -224,8 +224,7 @@ main(int argc, char **argv) struct smsg **slist, **flist; struct smsg ***il, **fp, **dp; - slist = (struct smsg **) - mh_xmalloc((nmsgs+1) * sizeof(*slist)); + slist = (struct smsg **) mh_xcalloc(nmsgs+1, sizeof(*slist)); memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist)); qsort((char *)slist, nmsgs, sizeof(*slist), (qsort_comp) subsort); @@ -244,8 +243,7 @@ main(int argc, char **argv) ** make up the final list, chronological but with ** all the same subjects grouped together. */ - flist = (struct smsg **) - mh_xmalloc((nmsgs+1) * sizeof(*flist)); + flist = (struct smsg **) mh_xcalloc(nmsgs+1, sizeof(*flist)); fp = flist; for (dp = dlist; *dp;) { struct smsg **s = il[(*dp++)->s_msg]; diff --git a/uip/spost.c b/uip/spost.c index 4a24fc4..a4c170b 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -319,7 +319,7 @@ main(int argc, char **argv) adios(EX_DATAERR, NULL, "message has no recipients"); } - sargv = mh_xmalloc(sizeof(char **) * (recipientsc + 4)); + sargv = mh_xcalloc(recipientsc + 4, sizeof(char **)); argp = sargv; *argp++ = "send-mail"; -- 1.7.10.4