| 288 | if (end == *p) return false; |
| 289 | *p = end; |
| 290 | *out = v; |
| 291 | return true; |
| 292 | } |
| 293 | |
| 294 | static bool json_int(const char **p, int *out) { |
| 295 | double v = 0.0; |
| 296 | if (!json_number(p, &v)) return false; |
| 297 | /* json_number() uses strtod(), which accepts "NaN"/"Infinity". NaN fails |
| 298 | * every comparison, so a plain `v < 0` clamp would let it through to the |
| 299 | * (int) cast, which is undefined for NaN; `!(v >= 0)` folds NaN (and |
| 300 | * negatives) to 0. +/-Infinity are handled by the two clamps. */ |
| 301 | if (!(v >= 0)) v = 0; |
| 302 | if (v > INT_MAX) v = INT_MAX; |
| 303 | *out = (int)v; |
| 304 | return true; |
no test coverage detected