[Bug libstdc++/33201] New: libstc++ togehter wiht uclibc cannot format double in iostream

g dot janak at unicontrol dot de gcc-bugzilla@gcc.gnu.org
Mon Aug 27 09:35:00 GMT 2007


Short Story:
With Current gcc/libstdc++ + uclibc you cannot put a float/double in a iostream
(f.e. cout)

Attached Patch fix this, because the size of the allocated Buffer given to
__convert_from_v is
needed from uclibc. If GLIBCXX_C99 is defined libstdc++ give the cs_size to the
function.


Long Story:

First i thought its an uclibc Bug:
http://bugs.busybox.net/view.php?id=1090

The problem was:
putting a double in a stream:
cout << 10.5 ;

Produce an empty string, or some garbage characters.

Searchign the reason I found locale_facets.tcc the do_put impleemtation which
is used for formating a double into a string in c++ iostream's. (gcc 4.2.1 :
line 1143) but its in all gcc 4.x.x i looked .


In the implementation the __convert_from_v the __cs_size is used.
You can verify this with the following testCode

#define protected public
#include <iostream>
using namespace std;

int main()
{
        float d=23.12;

        char * __cs = (char*) malloc(100);
        int __cs_size=100;
        char __fbuf[16]="%f";
        const streamsize __prec = 6;
        __c_locale loc;
        locale::facet::_S_create_c_locale(loc, "C");

        __convert_from_v(loc, __cs, 0, __fbuf, __prec, d);

        printf("test: %s\n",__cs);
        return 0;
}

This Fails in g++ + uclibc  on a PowerPC Architecture.


I hope I understand it correctly, i'm not very deep inside gcc/libstdc++
sources.

--- gcc-4.2.1/libstdc++-v3/include/bits/locale_facets.tcc.orig  2007-08-27
11:19:50.000000000 +0200
+++ gcc-4.2.1/libstdc++-v3/include/bits/locale_facets.tcc       2007-08-27
11:19:52.000000000 +0200
@@ -1143,7 +1143,7 @@
        const int __cs_size = __fixed ? __max_exp + __prec + 4
                                      : __max_digits * 2 + __prec;
        char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
-       __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, __fbuf, 
+       __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
__fbuf, 
                                      __prec, __v);
 #endif


-- 
           Summary: libstc++ togehter wiht uclibc cannot format double in
                    iostream
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: g dot janak at unicontrol dot de
 GCC build triplet: powerpc-linux-uclibc
GCC target triplet: powerpc-linux-uclibc


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33201



More information about the Gcc-bugs mailing list