[PATCH resend] webservices: Use sscanf to convert strings to doubles.
This removes the last "long double" instance impacted by commit 0e183cc3c0d3b6f89f79047cdd71c389afc75073. Thanks go again to Piotr for his help. Next time I'll remember to wait for the VMs to update ;) Best, Erich
Hi Erich, + if (p[len-1] == 'e' || p[len-1] == 'E') return WS_E_INVALID_FORMAT; /* "1e" */ This is no longer needed. scanf is now returning error on such input. Sorry I haven’t seen it earlier, Piotr
On Fri, 2020-01-03 at 17:08 -0700, Erich E. Hoover wrote:
+ if (*p == '+' || *p == '-') { - tmp = val * 10 + p[i] - '0'; - if (val > MAX_UINT64 / 10 || tmp < val) + if (len == 1 || (len == 2 && *(p+1) == '.')) { - for (; i < nb_digits; i++) exp++; - break; + ret = 0; + return S_OK; }
'ret' is a pointer.
+ ret = 0; + return S_OK;
Same here.
+ for (i = 0; i < len; i++) { - if (exp & 1) exp_val *= exp_mul; - exp_mul *= exp_mul; + if (p[i] >= '0' && p[i] <= '9') continue; + if (p[i] != 'e' && p[i] != 'E' && p[i] != '.' && p[i] != '+' && p[i] != '-') + return WS_E_INVALID_FORMAT; }
Is this part really necessary? I also get new failures with a non-mingw build: reader.c:3729: Test failed: 0: got 803d0000 reader.c:3729: Test failed: 1: got 803d0000 reader.c:3729: Test failed: 2: got 803d0000 reader.c:3729: Test failed: 8: got 803d0000 reader.c:3729: Test failed: 9: got 803d0000 reader.c:3729: Test failed: 10: got 803d0000 ... Looks like scanf returns a different result for %n in this case. It probably shouldn't block this patch though.
On Mon, Jan 6, 2020 at 3:52 AM Hans Leidekker <hans(a)codeweavers.com> wrote:
On Fri, 2020-01-03 at 17:08 -0700, Erich E. Hoover wrote:
... + ret = 0; ...
'ret' is a pointer.
Ack, sorry about that - supposed to be setting the value.
... + for (i = 0; i < len; i++) { - if (exp & 1) exp_val *= exp_mul; - exp_mul *= exp_mul; + if (p[i] >= '0' && p[i] <= '9') continue; + if (p[i] != 'e' && p[i] != 'E' && p[i] != '.' && p[i] != '+' && p[i] != '-') + return WS_E_INVALID_FORMAT; }
Is this part really necessary?
Technically sscanf supports more than what the reader does, but it does pass all the current tests without this check. For example, scanf supports the Fortran-style "d" exponent notation (for msvcr < 140). If you would like I can fold the +/-/. weirdness into this, which does have tests, possibly something like: === for (i = 0; i < len; i++) { if (p[i] >= '0' && p[i] <= '9') { found_digit = TRUE; continue; } if (p[i] != 'e' && p[i] != 'E' && p[i] != '.' && p[i] != '+' && p[i] != '-') return WS_E_INVALID_FORMAT; } if (!found_digit) { *ret = 0; return S_OK; } ===
I also get new failures with a non-mingw build: ... Looks like scanf returns a different result for %n in this case. It probably shouldn't block this patch though.
That's interesting, if you like I could move the length check into the format checker so that it does not rely on scanf for that to work properly. Best, Erich
On Mon, Jan 6, 2020 at 9:35 AM Erich E. Hoover <erich.e.hoover(a)gmail.com> wrote:
... That's interesting, if you like I could move the length check into the format checker so that it does not rely on scanf for that to work properly.
For example, the attached version. Best, Erich
participants (3)
-
Erich E. Hoover -
Hans Leidekker -
Piotr Caban