Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poco::format() misorders sign and padding specifiers #65

Closed
pprindeville opened this issue Jan 14, 2013 · 4 comments
Closed

Poco::format() misorders sign and padding specifiers #65

pprindeville opened this issue Jan 14, 2013 · 4 comments
Assignees
Milestone

Comments

@pprindeville
Copy link
Contributor

If I run in a debugger:

Poco::format("%+03d", -7)

I get "0-7" as the output. This is wrong.

This breaks down as:

stream << setiosflags(ios::showpos) << setfill('0') << setw(3) << -7 << endl;

which not surprisingly, generates the same incorrect response...

I'd recommend processing the sign separately in formatOne() for the specifier '+', i.e.

stream << setiosflags(ios::showpos) << setw(1) << -7

then resetting the ios::showpos flag and shaving 1 off the width, and setting the fill, then passing the value a 2nd time.

@obiltschnig
Copy link
Member

Proper solution is to use formatting flag std::ios::internal along with std::ios::showpos.
Fixed in develop and 1.4.6p2.

@aleks-f
Copy link
Member

aleks-f commented Jun 7, 2013

This change broke gcc 4.2, calls to format now hang. Reproduced on mac and FreeBSD, did not have time to investigate further.

@aleks-f aleks-f reopened this Jun 7, 2013
@ghost ghost assigned obiltschnig Jun 7, 2013
@obiltschnig
Copy link
Member

Can not reproduce this on my mac FormatTest works fine with gcc 4.2.

@aleks-f
Copy link
Member

aleks-f commented Jun 7, 2013

The problem seems to be in the order of declaration/definition of AnyCast functions:

template
ValueType AnyCast(const Any& operand)

// ...

template
ValueType AnyCast(Any& operand)

The first one, when called, goes tail-spinning in a recursive call. Looking at it, it makes sense but I'm not sure how/why did this work so far and started manifesting itself all of a sudden.

I'l fix this later.

@aleks-f aleks-f closed this as completed Jun 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants