From owner-freebsd-bugs Wed Oct 27 0:50: 2 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 4F70A152C4 for ; Wed, 27 Oct 1999 00:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id AAA34682; Wed, 27 Oct 1999 00:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Wed, 27 Oct 1999 00:50:01 -0700 (PDT) Message-Id: <199910270750.AAA34682@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Sheldon Hearn Subject: Re: bin/14472: date for Y#K Reply-To: Sheldon Hearn Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/14472; it has been noted by GNATS. From: Sheldon Hearn 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