Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Bug in Compiler?

$
0
0

I seem to have found a bug in the MS C++ 2010 compiler. It doesn't occur in the debug version, but does in the release version with or without the

optimizer turned on.

Here is a short program that produces the bug:
(shortened from a much longer program)

#include <STDIO.H>
#include <MATH.H>
#include <STRING.H>
#include <direct.h>
#include <windows.h>
#define MAXSAMP 32000
int main(int argc, char *argv[])
{ char inputline[_MAX_FNAME];
  char fmtsp,fmtxy; //8 bit integer
  unsigned char hbsp,hbx,hby;
  FILE *fin; //file pointers
  if(argc>1) //parameters file is given in command line
    strcpy_s (inputline,_MAX_FNAME,argv[1]);
  else
  { printf("Type the name of the file telling which seismic files to change & which header bytes to use\n");
    gets_s(inputline,_MAX_FNAME);
  }
  if ( (fin=fopen(inputline,"r")) == NULL )
  { printf("Can't open %s\n", inputline);
    exit(1);
  }
  fgets(inputline,_MAX_FNAME,fin);
  sscanf_s(inputline,"%d %c",&hbsp,&fmtsp,1);
printf("0 Shot Point format is %c\n",fmtsp);
  hbsp= (hbsp-1)/4;
printf("1 Shot Point format is %c\n",fmtsp);
  fgets(inputline,_MAX_FNAME,fin);
printf("2 Shot Point format is %c\n",fmtsp);
  sscanf_s(inputline,"%d %d %c",&hbx,&hby,&fmtxy,1);
printf("3 Shot Point format is %c\n",fmtsp);
  hbx=(hbx-1)/4;
  hby=(hby-1)/4;
  fcloseall();
  exit(0);
}

When the input file is:

17 B            :shotpoint header byte & format
181 185 I       :XY header bytes & format


The output from this program is:

0 Shot Point format is B
1 Shot Point format is B
2 Shot Point format is B
3 Shot Point format is

IE: somehow between the last 2 printf statements the variable 'fmtsp' gets changed from B to a blank space.

BTW I tried compiling on 2 different computers, one with Windows XP & one with Windows 7. The executable produced the same wrong results.



Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>