Usenet comp.sys.vms (1990-2004)
 help / color / mirror / Atom feed
From: Chris Waters <cwaters@systems.dhl.com>
Subject: Re: What do you look for in C/C++ source? tm_year?
Date: 1997/09/05	[thread overview]
Message-ID: <ckok9gvmmzz.fsf@systems.dhl.com> (raw)
In-Reply-To: 34101ba1.2323741@news.gate.net


abowers@X.gate.net (Al Bowers) writes:

> On Tue, 02 Sep 1997 11:45:38 -0400, David Means
> <dmeans@bellsouth.net.no_spam> 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?)



  parent reply	other threads:[~1997-09-05  4:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-02  4:00 What do you look for in C/C++ source? tm_year? David Means
1997-09-02  4:00 ` Eric Buckley
1997-09-03  4:00 ` John A. Kroll
1997-09-04  4:00 ` Arne Vajh�j
     [not found] ` <34101ba1.2323741@news.gate.net>
1997-09-05  4:00   ` Chris Waters [this message]
     [not found] <340C34B7.1BE36F49@bellsouth.net.no_spam>
     [not found] ` <340CAC2A.167E@stl.dec.com>
1997-09-03  4:00   ` Kaz Kylheku
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox