MCPcopy Create free account
hub / github.com/esnet/iperf / parse_number

Function parse_number

src/cjson.c:316–390  ·  view source on GitHub ↗

Parse the input text to generate a number, and populate the result into item. */

Source from the content-addressed store, hash-verified

314
315/* Parse the input text to generate a number, and populate the result into item. */
316static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer)
317{
318 double number = 0;
319 unsigned char *after_end = NULL;
320 unsigned char number_c_string[64];
321 unsigned char decimal_point = get_decimal_point();
322 size_t i = 0;
323
324 if ((input_buffer == NULL) || (input_buffer->content == NULL))
325 {
326 return false;
327 }
328
329 /* copy the number into a temporary buffer and replace '.' with the decimal point
330 * of the current locale (for strtod)
331 * This also takes care of '\0' not necessarily being available for marking the end of the input */
332 for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++)
333 {
334 switch (buffer_at_offset(input_buffer)[i])
335 {
336 case '0':
337 case '1':
338 case '2':
339 case '3':
340 case '4':
341 case '5':
342 case '6':
343 case '7':
344 case '8':
345 case '9':
346 case '+':
347 case '-':
348 case 'e':
349 case 'E':
350 number_c_string[i] = buffer_at_offset(input_buffer)[i];
351 break;
352
353 case '.':
354 number_c_string[i] = decimal_point;
355 break;
356
357 default:
358 goto loop_end;
359 }
360 }
361loop_end:
362 number_c_string[i] = '\0';
363
364 number = strtod((const char*)number_c_string, (char**)&after_end);
365 if (number_c_string == after_end)
366 {
367 return false; /* parse_error */
368 }
369
370 item->valuedouble = number;
371
372 /* use saturation in case of overflow */
373 if (number >= LLONG_MAX)

Callers 1

parse_valueFunction · 0.85

Calls 1

get_decimal_pointFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…