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



The information in this article applies to:

  • Microsoft LINK for MS-DOS
  • Microsoft LINK for OS/2

This article was previously published under Q67795

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);

}

Modification Type:MajorLast Reviewed:10/23/2003
Keywords:kb16bitonly KB67795 kbAudDeveloper