www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/12/22/10:11:28

Sender: <solyom AT bmeik DOT eik DOT bme DOT hu>
Date: Wed, 22 Dec 1993 15:17:56 +0100
From: solyom AT bmeik DOT eik DOT bme DOT hu
Reply-To: SOLYOM AT HUBME51 DOT bitnet
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Subject: SERIOUS problem with the 1.11 distribution

I found a SERIOUS bug in the new djgpp distribution (1.11)! If you are not
using the -Wall option to find out and eliminate all(!) warnings, 
your otherwise CORRECT C or C++ programs will not always execute
correctly! 

I could not found out the real cause of the problem so here is my story:

I am writing an image processing program that uses a GUI based on the
LIBGRX library. I have never encountered any problems with the pre 1.10
distributions. But since the new linker is introduced with version 1.10 some
of my functions started to behave erratically: e.g. buttons in some dialog 
boxes became vertical strips, windows were mixed up, etc. 
After some experimenting I found out that if I replaced the new linker  
with the one from 1.09 the problem just vanished! 
(I reported this problem to this list, but the only answer I got was that the 
new linker is more versatile than the old one, so it will be used from now on..)
Now with the new 1.11 release the problem came back again, but because 
the old linker cannot work with the COFF format (as I was told) I badly needed
a solution.

In a small function I have tried to open a file after checking its existence.
As the file existed the checking returned an OK code but the open failed!
Here is the code fragment I have used:

static FILE *fHelp;
static char *pb;
/*======================================================================*/
void DoSimpleHelp(char *pszHelpName)
/*----------------------------------------------------------------------*/
{
	struct stat st;
	char buff[222],buf1[80];		/* !!!!!! */

	if( stat(pszHelpName, &st) )
	{
		Error("File '%s' not found!\n", pszHelpName);
		return;
	}
	pb = calloc(st.st_size + 80 + 1, 1);
	if(!pb)
	{
		Error("Not enough memory!\n");
		return;
	}
	if( (fHelp = Fopen(pszHelpName, "r") ) == NULL)
	{
		Error("Cannot open the file !\n");
		return;
	}
		/* .... other program lines .... */

	Fclose(fHelp);
	free(pb);
	return;
}
(Error(), Fopen(), Fclose() are my functions.

The program reported that it 'Cannot open the file'! Debugging revealed that
the Fopen() call was not given the same file name as the stat() call.

Then I compiled the program with the -Wall switch and found out that I did
not used the two buffers defined at the top (see the !!!!). I deleted them
and my program started to run fine. I went throug the whole program and
corrected all warnings. These warnings mostly said that I perhaps need to
put braces around all AND (&&) cause in an ORed (||) expression, or that
I defined variables but did not use them, or MAYBE some variables are used
without initializing them  (which never was the case! I mostly used such
constructs as:
	LISTITEM *p, *p1;
	for(p = LIST->pFirstItem; p ; p = p1)
	{
		p1 = p->pNext;
		...
	}
).

After  eliminating all warnings my buttons became buttons again...

Now I do not know what is the problem! How can one linker create a bad file
from the object modules while the other one does not I cannot comprehend.
Is it a compiler or linker error OR is it a problem with the GO32 driver which
makes them execute incorrectly?

I tried to reproduce the problem with the function above without the other stuff
and in non graphics mode but failed. This seems to indicate a linker problem. 
(i.e. a problem when a lot of object modules are combined.)

(I use a 16 MB 33MHz 486 QEMM 7.02, and I had about 90 Mbytes of free disk 
space)




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019