Patch to fix uClibc++ stream issue

Peter Nixon listuser at peternixon.net
Fri Aug 22 12:37:53 UTC 2008


There is an issue in uClibc++ stream handling.

Two problems:

The fill character is uninitialized in one form of the ios constructor, so
sometimes output is filled with a random character rather than a space.

Unfortunately the test of the format flags == right is not the same flags
!= left, so code was rearranged to guarantee that if it is not left aligned
then it must be right aligned.

Background: This bug in uclibc++ causes OPAL to fail SIP authentication with 
a registrar if the MD5 Digest has a leading zero, but not otherwise. (Lots 
of fun to track down!!)

Index: include/ostream
===================================================================
--- include/ostream     (revision 1735)
+++ include/ostream     (working copy)
@@ -130,17 +130,17 @@
                }
 
                _UCXXEXPORT void printout(const char_type* s, streamsize n)
-                {
-                  int extra = ios::width() - n;
-                  if ((ios::flags()&ios::adjustfield) == ios::right)
-                    while (extra-- > 0)
-                      put(ios::fill());
-                  write(s, n);
-                  if ((ios::flags()&ios::adjustfield) == ios::left)
-                    while (extra-- > 0)
-                      put(ios::fill());
-                  ios::width(0);
-                }
+        {
+            bool printfirst = (ios::flags()&ios::adjustfield) == ios::left;
+            if (printfirst)
+                write(s, n);
+            int extra = ios::width() - n;
+            while (extra-- > 0)
+                put(ios::fill());
+            if (!printfirst)
+                write(s, n);
+            ios::width(0);
+        }
 
        protected:
                basic_ostream(const basic_ostream<charT,traits> &){ }
Index: include/ios
===================================================================
--- include/ios (revision 1735)
+++ include/ios (working copy)
@@ -344,7 +344,7 @@
                        init(sb);
                }
 
-               basic_ios() : mtied(0), mstreambuf(0){ }
+               basic_ios() : fill_char(' '), mtied(0), mstreambuf(0){ }
 
                virtual _UCXXEXPORT ~basic_ios(){
                }
 
-- 

Peter Nixon
http://peternixon.net/



More information about the uClibc mailing list