Skip to content

Bug in NumericString with decSep != '.' #3159

@stefanstocker

Description

@stefanstocker

In file
"poco/Foundation/src/NumericString.cpp"
within function
"void pad(std::string& str, int precision, int width, char prefix = ' ', char decSep = '.')"
it is programmed at nearly the beginning of the function that, if DecimalSeparator is not present in the string, always a '.' will be appended, nevertheless another char is set to decSep.
This happens in calls to functions
"doubleToStr, doubleToFixedStr, floatToStr, floatToFixedStr"
where decSep can be passed as parameter and if values with NO fraction should be converted (e.g. -1.0, 4.0, ...).

I think, changing the one line, which I have marked with "old with fixed ..." in the following code snippet, to "str.append(1, decSep);" should eliminate the problem.

...................

void pad(std::string& str, int precision, int width, char prefix = ' ', char decSep = '.')
/// Pads the string with prefix space and postfix 0.
/// Alternative prefix (e.g. zero instead of space) can be supplied by caller.
/// Used only internally.
{
// these cases should never happen, if they do, it's a library bug
poco_assert_dbg (precision > 0);
poco_assert_dbg (str.length());

std::string::size_type decSepPos = str.find(decSep);
if (decSepPos == std::string::npos)
{
	str.append(1, decSep);					//old with fixed '.' as decimal separator		str.append(1, '.');
	decSepPos = str.size() - 1;
}

...................

Thanks in advance,
best regards
Stefan Stocker

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions