Version:
m4 version 1.4, all operating systems

Problem description:
The format macro returns a wrong output if you specif an integer number that 
terminates with a 0, example try to output the number 10 using:
  > format(%f, 10)
  1000000

The problem is a bug in the formatting routine format.c:
The following loop is in charge to place the decimal point at the proper location, the 
pointer *s is initialized to the string returned by fcvs() whereas trailing zeros are
pruned by clr0(). So for the number 10, s points to the string "1" and decptr is 3, so 
the while loop will simply return the string "1" instead of "10.".
                while (--decpt >= 0)
                  *s++ = *t++;
                if (n > 0 || alternate)
                  *s++ = '.';

Solution:
The patch that solves the problem:
453c453
<               while (--decpt >= 0)
---
>               while (*t && --decpt >= 0)
454a455,456
>               while (--decpt>=0)
>                 *s++ = '0';

And here we go, the proper result for printing the number 10 is:
> format(%f,10)
10.000000

One thing I don't understand is why the format command has an own implementation, 
wouldn't it be better to simply use vsprintf() instead ?
My guess is that vsprintf() is not implemented or not consistent on all operating 
systems ?

Regards,

Roderick Koehle

---

Roderick Koehle
Infineon Technologies AG, C LITHO TD
Balanstr. 73
81541 Muenchen
Tel:  ++49 (89) 234 20746  
Fax: ++49 (89) 234 714269 
mailto:[EMAIL PROTECTED]




_______________________________________________
Bug-m4 mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-m4

Reply via email to