www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000109

When Created: 09/10/1996 03:08:56
Against DJGPP version: 2.00
By whom: tburgess@drao.nrc.ca
Abstract: atof() and strtod() can cause FP stack overflow
atof() and strtod() do not clean up the FP stack. After 8 calls to either
or a few calls followed by other FP stack usage, the stack overflows.
This occurs also with the newer libm.a version that fixes other problems.

#include <stdio.h>
#include <math.h>

// demo of atof() and strtod() FP stack problem
void main()
{
	double a[9];
	char *ainit = "3.1415";
	int i; 
	
	for (i = 0; i < 9; i++)	// FP stack is 8 deep
		{
		a[i] = atof(ainit);		//overflows FP stack
		//a[i] = strtod(ainit);		//overflows FP stack
		//sscanf(ainit, "%lf", &(a[i]));//works
		}
	printf("last value was %f\n", a[8]);
}

Workaround added: 09/10/1996 03:12:27
By whom: tburgess@drao.nrc.ca
sscanf seems to work as a substitute for atof.

double var;
sscanf(buffer, "%lf", &var);

Note added: 09/11/1996 19:42:20
By whom: terra@diku.dk (Morten Welinder)
This looks like a consequence of bug 80 which is fixed in WIP.

Solution added: 09/12/1996 01:51:32
By whom: tburgess@drao.nrc.ca
Never again will I confuse -w (compiler warnings off) with -W (extra warnings)!!
Had I not had -w checked, I would have spotted the implicit declarations
of atof, etc. noticed that I needed <stdlib.h>, not <math.h>, found that
strtod was missing a parameter, and saved myself a lot of time. (atof
returned result on FP stack, int result was expected in EAX, hence no pop.
I hope no one else wasted much time on this. Please remove this bogus bug
from the system. If you feel that moving it to the closed section as a
warning to other foolish mortals would serve the common good, I can live
with that ... I guess.  - regards, tom.

Closed on 09/13/1996 22:19:44: user error
By whom: dj@delorie.com



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010