From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,5e0ef8d936a38c44 X-Google-Attributes: gidf7344,public X-Google-Thread: fc89c,5e0ef8d936a38c44 X-Google-Attributes: gidfc89c,public X-Google-Thread: f86b3,5e0ef8d936a38c44 X-Google-Attributes: gidf86b3,public X-Google-Thread: fc7fa,5e0ef8d936a38c44 X-Google-Attributes: gidfc7fa,public X-Google-Thread: 1014db,5e0ef8d936a38c44 X-Google-Attributes: gid1014db,public From: Chris Waters Subject: Re: What do you look for in C/C++ source? tm_year? Date: 1997/09/05 Message-ID: #1/1 X-Deja-AN: 270078177 Sender: cwaters@tango References: <340C34A2.FD0EE69F@bellsouth.net.no_spam> <34101ba1.2323741@news.gate.net> Organization: DHL Systems, Inc. Newsgroups: comp.software.year-2000,comp.unix.programmer,comp.os.vms,comp.sys.vms,comp.lang.c abowers@X.gate.net (Al Bowers) writes: > On Tue, 02 Sep 1997 11:45:38 -0400, David Means > wrote: > > >If you're greping through 1000's of lines of ( C/C++ ) code for date related > >bugs, what do you look for? My first assumption is to find tm_year. > > > >What other stuff do you look for? > > > Look and see if you have the header file > time.h included. > If time.h is included, search for and follow time_t > and struct tm values. > Al Bowers > Tampa, FL > mailto: abowers@combase.com > http://www.gate.net/~abowers/index.html Actually, most of the date related bugs I've seen in C/C++ code involve code which DOESN'T include time.h, but which defines its own local prototypes for time() and ctime() or asctime(). If I were going to grep, I'd just grep for "time". That may give you a lot of hits, so pay close attention to any code which calls ctime() or asctime(). It seems to be a common bad trick to parse the two-digit year out of the strings these return. Unfortunately, most code which uses any of the functions or structures found in time.h (even if the header is not included, as I mentioned above) is *not* where the date related bugs in C/C++ code are found. Most of the bugs involve 2-digit dates stored in files, which are hand parsed. And unfortunately, there's no obvious way to grep for these. If you're lucky, grepping for "year" may reveal some of these, but it's not guaranteed. Also grep for "date", which may be used as a variable name in buggy code, and may also be used in system() calls in buggy code running under UNIX (one of the newsgroups this appears in is comp.unix.programmer). After you've done the above, *then* look for struct tm. The common bug here is to assume that the tm_year field contains a value between 0 and 99, rather than the number of years since 1900. After you've done *that* then you might want to check out "time_t". Although there are millions of lines of code out there which use "long" where they should be using time_t. I have a hard time persuading people -- even today! -- that they should be using the proper headers and data types to handle time values. Many older C programmers seem to be unaware that time() doesn't take and return a long. And finally, as a last step, free associate, and scan the code at random, looking for more of those accesses to two digit years stored in files. Only perserverance, insight, and luck will allow all of these bugs to be found. (Isn't this all in a FAQ somewhere?)