On 09/15/2010 10:45 AM, Paolo Bonzini wrote:
On 09/15/2010 02:23 PM, jes.soren...@redhat.com wrote:
switch (*endptr++) {
case 'K':
case 'k':
value<<= 10;
break;
case 0:
+ if (divider) {
+ value = 0;
+ break;
+ }
case 'M':
case 'm':
value<<= 20;
@@ -284,9 +306,12 @@ uint64_t strtobytes(const char *nptr, char **end)
default:
value = 0;
}
+ if (divider)
+ value /= divider;
This risks overflow if you do 1.00000000000000G or something similarly
braindead. Do we loathe floating point so much that you cannot use
strtod, like
It should be strtod. Only badness can happen otherwise.
Regards,
Anthony Liguori
endptr1 = nptr + strspn(s, "0123456789.");
switch (*endptr1)
{
case 0: divider = 1; break;
case 'm': divider = 1 << 20; break;
...
default: /* error, including for 1.0e+5 and negative */
}
value = (uint64_t) (strtod(nptr, &endptr2) / divider);
if (endptr1 != endptr2) /* error, e.g. 1.2.3 */
return value;
Paolo