Microsoft KB Archive/116210

{|
 * width="100%"|

BUG: mktime May Cause R6003 "integer divide by 0" Error

 * }

Q116210

-

The information in this article applies to:


 * The C Run-Time (CRT), included with:
 * Microsoft Visual C++, versions 1.0, 1.5

-

SYMPTOMS
When you call mktime with any time between 00:00:00 and 01:00:00 on 1/1/1970, with the TZ environment variable set to LOC000000 (Greenwich Mean Time), the following error messages display:

Under MS-DOS:

      run-time error - integer divide by 0

Under Windows:

      Application Error - integer divide by 0

STATUS
Microsoft has confirmed this to be a bug in the products listed above. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

This is not a problem in the Visual C++ 32-bit Edition.

MORE INFORMATION
The following sample code demonstrates how to reproduce this problem:

Sample Code
/* /* COMMAND LINE: /* DESCRIPTION: mktime gives r6003 for time < 01:00:00 Jan. 1, 1970 /*           Be sure that environment variable TZ=LOC000000 GMT /*

#include   #include 

#define START_TIME 3605L

void main(void) {    time_t reference; struct tm tblk; char buf[40];

/* get current TZ environment variable (TZ=LOC000000 on my system: GMT) */ _tzset;

/* init reference time to 01/01/1970 at 01:00:05 */ reference = START_TIME;

/* assign daylight savings time value */ tblk.tm_isdst = _daylight;

/* loop downwards from initial reference time */ for (reference = START_TIME;reference >= 0L; reference--) {       tblk = *localtime(&reference);

strftime(buf, 39, "%c", &tblk); printf("struct tm contents from localtime: %s\n", buf);

/* NOTE: mktime generates divide by 0 error for reference seconds less than 3600 */ reference = mktime(&tblk); printf("seconds from struct tm using mktime: %ld\n", reference); }

} Additional query words: 1.00 1.50

Keywords : kb16bitonly

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCRT