1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-05-04 16:34:12 +00:00

fix defect detected by coverity scan

aStr->find('.', startPos) can return a negative number, but idx was
passed to a parameter that cannot be negative. Now the function returns
the string as is in case of no decimal point found.
This commit is contained in:
Carles Fernandez 2016-01-06 14:30:15 +01:00
parent 5b2645a964
commit 5743f0f631

View File

@ -515,9 +515,10 @@ inline std::string & Rinex_Printer::sci2for(std::string & aStr,
bool redoexp =! checkSwitch;
// Check for decimal place within specified boundaries
if ((idx == 0) || (idx >= (startPos + length - expLen - 1)))
if ((idx <= 0) || (idx >= (startPos + length - expLen - 1)))
{
// Error: no decimal point in string
return aStr;
}
// Here, account for the possibility that there are
@ -525,12 +526,12 @@ inline std::string & Rinex_Printer::sci2for(std::string & aStr,
// account for the possibility of non-scientific
// notation (more than one digit to the left of the
// decimal)
if ((idx > startPos) && (idx >= 1))
if (idx > startPos)
{
redoexp = true;
// Swap digit and decimal.
aStr[static_cast<unsigned int>(idx)] = aStr[static_cast<unsigned int>(idx - 1)];
aStr[static_cast<unsigned int>(idx - 1)] = '.';
aStr[idx] = aStr[idx - 1];
aStr[idx - 1] = '.';
// Only add one to the exponent if the number is non-zero
if (asDouble(aStr.substr(startPos, length)) != 0.0)
expAdd = 1;