Date: Wed, 27 Oct 1999 00:50:01 -0700 (PDT) From: Sheldon Hearn <sheldonh@uunet.co.za> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/14472: date for Y#K Message-ID: <199910270750.AAA34682@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/14472; it has been noted by GNATS. From: Sheldon Hearn <sheldonh@uunet.co.za> To: freebsd-gnats-submit@freebsd.org Cc: Subject: Re: bin/14472: date for Y#K Date: Wed, 27 Oct 1999 09:42:29 +0200 BDE pointed out unsafe use of the post-increment operator in my diff. This one should be safe. Ciao, Sheldon. Index: date.c =================================================================== RCS file: /home/ncvs/src/bin/date/date.c,v retrieving revision 1.30 diff -u -d -r1.30 date.c --- date.c 1999/08/27 23:13:59 1.30 +++ date.c 1999/10/27 07:41:09 @@ -175,6 +175,8 @@ } #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; +#define ATOI4(ar) ((ar)[0] - '0') * 1000 + ((ar)[1] - '0') * 100 + \ + ((ar)[2] - '0') * 10 + ((ar)[3] - '0'); (ar) += 4; void setthetime(fmt, p, jflag, nflag) const char *fmt; @@ -221,11 +223,16 @@ /* if p has a ".ss" field then let's pretend it's not there */ switch (strlen(p) - ((dot != NULL) ? 3 : 0)) { + case 12: /* cc */ + lt->tm_year = -1900 + ATOI4(p); + if (lt->tm_year < 0) + badformat(); + goto year_done; case 10: /* yy */ lt->tm_year = ATOI2(p); if (lt->tm_year < 69) /* hack for 2000 ;-} */ lt->tm_year += 100; - /* FALLTHROUGH */ +year_done: /* FALLTHROUGH */ case 8: /* mm */ lt->tm_mon = ATOI2(p); if (lt->tm_mon > 12) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199910270750.AAA34682>