skip everything after and including dot when parsing int values

This commit is contained in:
john30
2015-12-10 08:21:09 +01:00
parent c43a83d192
commit f26e1d0835
2 changed files with 5 additions and 3 deletions
+3 -3
View File
@@ -1115,7 +1115,7 @@ result_t NumberDataField::writeSymbols(istringstream& input,
return RESULT_ERR_EOF; // input too short
else {
char* strEnd = NULL;
if (m_divisor >= 0 && m_divisor <= 1) {
if (m_divisor == 1) {
if ((m_dataType.flags & SIG) != 0) {
long int signedValue = strtol(str, &strEnd, 10);
if (signedValue < 0 && m_bitCount != 32)
@@ -1125,7 +1125,7 @@ result_t NumberDataField::writeSymbols(istringstream& input,
}
else
value = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0)
if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
return RESULT_ERR_INVALID_NUM; // invalid value
} else {
char* strEnd = NULL;
@@ -1261,7 +1261,7 @@ result_t ValueListDataField::writeSymbols(istringstream& input,
char* strEnd = NULL; // fall back to raw value in input
unsigned int value;
value = (unsigned int)strtoul(str, &strEnd, 10);
if (strEnd == NULL || strEnd == str || *strEnd != 0)
if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
return RESULT_ERR_INVALID_NUM; // invalid value
if (m_values.find(value) != m_values.end())
return writeRawValue(value, baseOffset, output);
+2
View File
@@ -153,6 +153,7 @@ int main()
{"x,s,uch", "0", "1025ffff00", "0100", ""},
{"x,s,uch,,,,y,m,uch", "3;2","1025ffff0103", "0102", ""},
{"x,,uch", "38", "10feffff0126", "00", ""},
{"x,,uch", "38.5", "10feffff0126", "00", "R"},
{"x,,uch", "0", "10feffff0100", "00", ""},
{"x,,uch", "254", "10feffff01fe", "00", ""},
{"x,,uch", "-", "10feffff01ff", "00", ""},
@@ -235,6 +236,7 @@ int main()
{"x,,bi3:2,1=on","on", "10feffff0108", "00", ""},
{"x,,bi3:2,1=on","-", "10feffff0100", "00", ""},
{"x,,bi3:2,0=off;1=on;2=auto;3=eco","auto", "10feffff0110", "00", ""},
{"x,,bi3:2,0=off;1=on;2=auto;3=eco","2.5", "10feffff0110", "00", "R"},
{"x,,bi3:2,0=off;1=on","on", "10feffff0108", "00", ""},
{"x,,bi3:2,0=off;1=on","off","10feffff0100", "00", ""},
{"x,,bi3:2,0=off;1=on","1", "10feffff0108", "00", "n"},