Skip to content

std::ios_base::floatfield misused in jsontest.h #1078

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

Closed
BillyDonahue opened this issue Nov 3, 2019 · 2 comments
Closed

std::ios_base::floatfield misused in jsontest.h #1078

BillyDonahue opened this issue Nov 3, 2019 · 2 comments
Assignees

Comments

@BillyDonahue
Copy link
Contributor

BillyDonahue commented Nov 3, 2019

TestResult operator<< uses

oss.setf(std::ios_base::floatfield);

This is inappropriate. The ios_base::floatfield is a mask, not a value.
This essentially selects hexfloat output, but if we wanted to do that we should do it explicitly.

Reproduce

This essentially what our TestResult operator is doing:

https://gcc.godbolt.org/z/e93L45

#include <iostream>
int main() {
    std::cout.setf(std::ios_base::floatfield);
    std::cout << "f:" << 3.14 << std::endl;
}
Output:
f:0x1.91eb851eb851fp+1

Expected behavior
I think we didn't want hexfloat output, or we would have asked for it by name.
I'm guessing the intent was to clear the floatfield, and we do that with unsetf.

None of our unit tests actually call operator<< with a floating point value, so it never mattered. We should fix the bug anyway.

@cdunn2001
Copy link
Contributor

cdunn2001 commented Nov 4, 2019

floatfield came from:

commit f587e6a420c467a69b7f977875052077aef2913b
Author: Baptiste Lepilleur <[email protected]>
Date:   Thu May 26 15:55:24 2011

    Fixed compilation issues with MSVC 6: replace usage of ostringstream with valueToString to support 64 bits integer and high precision floating point conversion to string.

I guess nobody else ever thought to check it! I merged your PR. You can close this, or leave it open to try << with a float.

@BillyDonahue
Copy link
Contributor Author

fixed by 638ad26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants