* Re: Logic error in mandoc.c time2a() [not found] ` <20110312002738.GA12289@iris.usta.de> @ 2011-03-12 1:59 ` Ingo Schwarze 2011-03-14 17:06 ` Kristaps Dzonsons 0 siblings, 1 reply; 2+ messages in thread From: Ingo Schwarze @ 2011-03-12 1:59 UTC (permalink / raw) To: uqs; +Cc: tech > I need to cook a diff... Index: mandoc.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mandoc.c,v retrieving revision 1.22 diff -u -p -r1.22 mandoc.c --- mandoc.c 7 Mar 2011 01:35:33 -0000 1.22 +++ mandoc.c 12 Mar 2011 01:56:00 -0000 @@ -382,29 +382,29 @@ static char * time2a(time_t t) { struct tm tm; - char buf[DATESIZE]; - char *p; - size_t nsz, rsz; + char *buf, *p; + size_t ssz; int isz; localtime_r(&t, &tm); - p = buf; - rsz = DATESIZE; + p = buf = mandoc_malloc(10 + 4 + 4 + 1); - if (0 == (nsz = strftime(p, rsz, "%B ", &tm))) - return(NULL); - - p += (int)nsz; - rsz -= nsz; - - if (-1 == (isz = snprintf(p, rsz, "%d, ", tm.tm_mday))) - return(NULL); + if (0 == (ssz = strftime(p, 10 + 1, "%B ", &tm))) + goto fail; + p += (int)ssz; + if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm.tm_mday))) + goto fail; p += isz; - rsz -= isz; - return(strftime(p, rsz, "%Y", &tm) ? buf : NULL); + if (0 == strftime(p, 4 + 1, "%Y", &tm)) + goto fail; + return(buf); + +fail: + free(buf); + return(NULL); } @@ -426,7 +426,7 @@ mandoc_normdate(char *in, mandocmsg msg, t = 0; } out = t ? time2a(t) : NULL; - return(mandoc_strdup(out ? out : in)); + return(out ? out : mandoc_strdup(in)); } -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Logic error in mandoc.c time2a() 2011-03-12 1:59 ` Logic error in mandoc.c time2a() Ingo Schwarze @ 2011-03-14 17:06 ` Kristaps Dzonsons 0 siblings, 0 replies; 2+ messages in thread From: Kristaps Dzonsons @ 2011-03-14 17:06 UTC (permalink / raw) To: tech; +Cc: Ingo Schwarze, uqs > + p = buf = mandoc_malloc(10 + 4 + 4 + 1); > > - if (0 == (nsz = strftime(p, rsz, "%B ",&tm))) > - return(NULL); > - > - p += (int)nsz; > - rsz -= nsz; > - > - if (-1 == (isz = snprintf(p, rsz, "%d, ", tm.tm_mday))) > - return(NULL); > + if (0 == (ssz = strftime(p, 10 + 1, "%B ",&tm))) > + goto fail; > + p += (int)ssz; > > + if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm.tm_mday))) > + goto fail; > p += isz; > - rsz -= isz; > > - return(strftime(p, rsz, "%Y",&tm) ? buf : NULL); > + if (0 == strftime(p, 4 + 1, "%Y",&tm)) > + goto fail; > + return(buf); > + > +fail: > + free(buf); > + return(NULL); Ingo, I'm fine with the motion of this diff, but please thoroughly document the numbers in this before you commit. Yes, they're clear upon inspection, but I want more in there than 10 + 4 + 4 + 1... But given this, ok kristaps. Thanks! Kristaps -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-03-14 17:07 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20110311204204.GA85668@acme.spoerlein.net> [not found] ` <20110312002738.GA12289@iris.usta.de> 2011-03-12 1:59 ` Logic error in mandoc.c time2a() Ingo Schwarze 2011-03-14 17:06 ` Kristaps Dzonsons
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).