From: David Levine Date: Sun, 5 Oct 2014 03:43:21 +0000 (-0500) Subject: Fixed commit 2adafe760a9c45b417727a3f5d9481de26471a8b to not X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/99873064b5f03ef92885f5e5fcadb4374c39a9ef?ds=inline;hp=--cc Fixed commit 2adafe760a9c45b417727a3f5d9481de26471a8b to not try to allocate a charstring_t of length INT_MAX with -width 0. --- 99873064b5f03ef92885f5e5fcadb4374c39a9ef diff --git a/uip/ap.c b/uip/ap.c index 3dd77b17..b231a0eb 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -112,11 +112,11 @@ main (int argc, char **argv) if ((width = sc_width ()) < WIDTH / 2) { /* Default: width of the terminal, but at least WIDTH/2. */ width = WIDTH / 2; - } else if (width == 0) { - /* Unlimited width. */ - width = INT_MAX; } width -= 2; + } else if (width == 0) { + /* Unlimited width. */ + width = INT_MAX; } fmt_compile (nfs, &fmt, 1); @@ -169,19 +169,20 @@ process (char *arg, int length) } for (p = pq.pq_next; p; p = q) { - charstring_t scanl = charstring_create (length); + charstring_t scanl = + charstring_create (length < NMH_BUFSIZ ? length : NMH_BUFSIZ); cptr = fmt_findcomp ("text"); if (cptr) { if (cptr->c_text) - free(cptr->c_text); + free(cptr->c_text); cptr->c_text = p->pq_text; p->pq_text = NULL; } cptr = fmt_findcomp ("error"); if (cptr) { if (cptr->c_text) - free(cptr->c_text); + free(cptr->c_text); cptr->c_text = p->pq_error; p->pq_error = NULL; } diff --git a/uip/dp.c b/uip/dp.c index 2e071973..cf8f9b14 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -108,11 +108,11 @@ main (int argc, char **argv) if ((width = sc_width ()) < WIDTH / 2) { /* Default: width of the terminal, but at least WIDTH/2. */ width = WIDTH / 2; - } else if (width == 0) { - /* Unlimited width. */ - width = INT_MAX; } width -= 2; + } else if (width == 0) { + /* Unlimited width. */ + width = INT_MAX; } fmt_compile (nfs, &fmt, 1); @@ -136,7 +136,8 @@ static int process (char *date, int length) { int status = 0; - charstring_t scanl = charstring_create (length); + charstring_t scanl = + charstring_create (length < NMH_BUFSIZ ? length : NMH_BUFSIZ); register struct comp *cptr; cptr = fmt_findcomp ("text"); diff --git a/uip/scansbr.c b/uip/scansbr.c index 749743c1..afc09011 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -75,7 +75,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, width = INT_MAX; } dat[3] = slwidth = width; - *scanl = charstring_create (width); + *scanl = charstring_create (width < NMH_BUFSIZ ? width : NMH_BUFSIZ); if (outnum) umask(~m_gmprot());