This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gnu-library: string-handling error ?


Hi,

I did choose this way to report since the gcc-compiler doesn't crash
but produces code that handles strings in a peculiar way. 
So there might be something wrong in one of the c-libraries.
I have attached a file with the code and some output.

I also noticed some peculiar output when I tried to concat
the string returned from floatTimeToString():
    sprintf(string, "Yellow color: 0 .. %s", floatTimeToString());
The runtime error here was segmentation error.  

regards,  Magnus
/*
gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --enable-__cxa_atexit --with-system-zlib --enable-nls --without-included-gettext --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-13)
*/

double speedIntervalF = 0.0; 
double timePkm = 0.0;

timePkm = 3.5;  //(f.ex)
speedIntervalF = 8 // (f.ex)

 
static char* floatTimeToString(double floatValue) 
  {  
    int i = 1;
    
    
    while((floatValue - i) > 0)
    {
      i++;
    }
    if((floatValue - i) == 0)
    {
      sprintf(stringValue, "%d.00 min/km", i);
      return (stringValue);
    }else
    if((floatValue - i) < 0)
    {
      sprintf(stringValue, "%d.%2.0f min/km", (i - 1), ((floatValue - (i - 1)) * 60));
      return (stringValue);
    }else
      return ("0.00 min/km");
    
  }


 g_print("Yellow colour: %s .. %s\n",
           floatTimeToString(timePkm - (speedIntervalF / 60)),
	   floatTimeToString(timePkm + (speedIntervalF / 60)));


  Estimated output from g_print:
  Yellow colour: 3.22 min/km .. 3.38 min/km
  
  Actual output:
  Yellow colour: 3.22 min/km .. 3.22 min/km
  

  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]