Bug 38210 - num_put<>::do_put(void*) performs padding incorrectly when adjustfield==internal
Summary: num_put<>::do_put(void*) performs padding incorrectly when adjustfield==internal
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.4.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-21 08:49 UTC by Andrey Tsyvarev
Modified: 2008-11-23 14:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-11-21 09:19:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Tsyvarev 2008-11-21 08:49:12 UTC
The following num_put<> member function

iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const 

incorrectly performs padding of a string to bring its length to the required value if 'adjustfield' flag is equal to 'internal': instead of adding fill characters after "0x" it adds them at the beginning of the string 

According to the description of padding options (22.2.2.2.2 p19), if 

adjustfield == internal and representation after stage 1 began with 0x or 0X - pad after x or X.

Example:

#include <iostream>
#include <locale>

using namespace std;
int main()
{
    void *p = (void*)0x1;
    cout.width(5);
    cout << internal << p << endl;
    return 0;
}
output "  0x1" while it should be "0x  1"
Comment 1 Paolo Carlini 2008-11-21 09:19:23 UTC
Yes.
Comment 2 paolo@gcc.gnu.org 2008-11-21 10:00:33 UTC
Subject: Bug 38210

Author: paolo
Date: Fri Nov 21 09:59:17 2008
New Revision: 142085

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142085
Log:
2008-11-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/38210
	* include/bits/locale_facets.tcc (num_put<>::do_put(iter_type,
	ios_base&, char_type, const void*)): Fix.
	* testsuite/22_locale/num_put/put/char/38210.cc: New.
	* testsuite/22_locale/num_put/put/wchar_t/38210.cc: Likewise.

Added:
    trunk/libstdc++-v3/testsuite/22_locale/num_put/put/char/38210.cc
    trunk/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/38210.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/locale_facets.tcc

Comment 3 Paolo Carlini 2008-11-21 10:00:54 UTC
Fixed for 4.4.0.
Comment 4 Dominique d'Humieres 2008-11-23 11:12:01 UTC
On *-apple-darwin9, the following tests are now failing:

FAIL: 22_locale/num_put/put/char/38210.cc execution test
FAIL: 22_locale/num_put/put/wchar_t/38210.cc execution test
Comment 5 Dominique d'Humieres 2008-11-23 12:02:25 UTC
Apparently the failures I have reported in comment #4 disappear if I rebuild libstdc++. Sorry for the noise.
Comment 6 Paolo Carlini 2008-11-23 14:01:34 UTC
(In reply to comment #5)
> Apparently the failures I have reported in comment #4 disappear if I rebuild
> libstdc++.

Not surprising ;)