Date: Sun, 6 Sep 1998 12:37:12 +0300 (IDT) From: Eli Zaretskii To: OoHOSEoO cc: djgpp AT delorie DOT com Subject: Re: SIGSEGV from reading an executable... (?) In-Reply-To: <1998090501154700.VAA20831@ladder01.news.aol.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On 5 Sep 1998, OoHOSEoO wrote: > Exiting due to signal SIGSEGV > Stack Fault at eip=00001700 > eax=00001c78 ebx=009c4040 ecx=009b7f15 edx=009b7f74 esi=00000054 edi=0000d4c0 > ebp=46464646 esp=009b7f80 program=C:\MYSTUFF\BINARY.EXE Both the "Stack Fault" and the preposterously messed up value of EBP suggest that you are trashing the stack. So you should be looking for a function that writes past the end of some automatic array. Here's the villain: > void convert(int Byte, char* HI, char* LO) > { > char chr[3]; > int status = 0; > > sprintf(chr, "%X", Byte); The declaration of chr[] assumes that Byte will use at most 2 characters to print. However, since Byte is an int, you cannot rely on that: the C promotion rules might cause a byte like 0xff be promoted to an int as 0xffffffff. In that case, sprintf will overwrite the stack frame, and KABOOM! One way to make this problem go away, you need to explicitly mask off all the bits beyond the low 8: sprintf (chr, "%X", Byte & 0xff);