EXE File Checksum Incorrect If LINK /CO or /E Option Used

Last reviewed: July 17, 1997
Article ID: Q67795
3.x 4.0x 4.10 5.0x 5.1x | 5.0x 5.10 5.13
MS-DOS                  | OS/2
kbtool kbcode

The information in this article applies to:

  • Microsoft LINK for MS-DOS, versions 3.x, 4.0x, 4.1, 5.0x, 5.1x
  • Microsoft LINK for OS/2, versions 5.0x, 5.1, and 5.13

SUMMARY

According to "The MS-DOS Encyclopedia," an MS-DOS .EXE file contains a checksum value in its .EXE file header. This checksum value should make the sum of all words in the .EXE file equal FFFFh. However, if the LINK command line specifies the /CODEVIEW or /EXEPACK options, LINK does not calculate the checksum correctly. Because current versions of MS-DOS ignore this checksum, this does not cause any noticeable problems.

Note that Microsoft LINK versions 5.3 and later do not compute a checksum value. The reserved bytes in the .EXE header are set to zero.

MORE INFORMATION

The following code example calculates the checksum for a specified MS-DOS executable file.

Sample Code

#include <stdio.h>
#include <stdlib.h>

main (int argc, char * argv[]) {
   FILE * fp;
   unsigned int nxt = 0, sum = 0;
   unsigned char bl, bh;

   if (argc != 2)
      exit(-1);
   if ((fp = fopen(argv[1], "rb")) == NULL)
      exit(-1);
   while (!feof(fp))
   {
      bl = fgetc(fp);
      if (!feof(fp))
         bh = fgetc(fp);
      else
         {
         bl = 0;
         bh = 0;
         }
      sum = sum + nxt;
      nxt = (unsigned int)bh * 256U + (unsigned int)bl;
   }
   nxt &= 0xFF;
   sum += nxt;
   printf("sum = %X\n", sum);
}


Additional reference words: kbinf 3.x 4.0x 4.10 5.0x 5.10 5.13 5.1x
LinkIss
KBCategory: kbtool kbcode
KBSubcategory: LinkIss
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 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.