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

Last reviewed: July 22, 1997
Article ID: Q116210
1.00 1.50 WINDOWS kbprg kbbuglist

The information in this article applies to:

  • The C Run-time (CRT), included with: Microsoft Visual C++ for Windows, versions 1.0 and 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 <stdio.h>
   #include <time.h>

   #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 reference words: 1.00 1.50
KBCategory: kbprg kbbuglist
KBSubcategory: CRTIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.