diff options
Diffstat (limited to 'src/lib/mhd_str.c')
-rw-r--r-- | src/lib/mhd_str.c | 347 |
1 files changed, 179 insertions, 168 deletions
diff --git a/src/lib/mhd_str.c b/src/lib/mhd_str.c index d0b03ead..6f2d7b98 100644 --- a/src/lib/mhd_str.c +++ b/src/lib/mhd_str.c | |||
@@ -117,8 +117,8 @@ _MHD_static_inline bool | |||
117 | isasciixdigit (char c) | 117 | isasciixdigit (char c) |
118 | { | 118 | { |
119 | return isasciidigit (c) || | 119 | return isasciidigit (c) || |
120 | ( (c >= 'A') && (c <= 'F') ) || | 120 | ( (c >= 'A') && (c <= 'F') ) || |
121 | ( (c >= 'a') && (c <= 'f') ); | 121 | ( (c >= 'a') && (c <= 'f') ); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
@@ -181,7 +181,7 @@ _MHD_static_inline int | |||
181 | todigitvalue (char c) | 181 | todigitvalue (char c) |
182 | { | 182 | { |
183 | if (isasciidigit (c)) | 183 | if (isasciidigit (c)) |
184 | return (unsigned char)(c - '0'); | 184 | return (unsigned char) (c - '0'); |
185 | 185 | ||
186 | return -1; | 186 | return -1; |
187 | } | 187 | } |
@@ -198,11 +198,11 @@ _MHD_static_inline int | |||
198 | toxdigitvalue (char c) | 198 | toxdigitvalue (char c) |
199 | { | 199 | { |
200 | if (isasciidigit (c)) | 200 | if (isasciidigit (c)) |
201 | return (unsigned char)(c - '0'); | 201 | return (unsigned char) (c - '0'); |
202 | if ( (c >= 'A') && (c <= 'F') ) | 202 | if ( (c >= 'A') && (c <= 'F') ) |
203 | return (unsigned char)(c - 'A' + 10); | 203 | return (unsigned char) (c - 'A' + 10); |
204 | if ( (c >= 'a') && (c <= 'f') ) | 204 | if ( (c >= 'a') && (c <= 'f') ) |
205 | return (unsigned char)(c - 'a' + 10); | 205 | return (unsigned char) (c - 'a' + 10); |
206 | 206 | ||
207 | return -1; | 207 | return -1; |
208 | } | 208 | } |
@@ -216,7 +216,7 @@ toxdigitvalue (char c) | |||
216 | * @return boolean true if character is lower case letter, | 216 | * @return boolean true if character is lower case letter, |
217 | * boolean false otherwise | 217 | * boolean false otherwise |
218 | */ | 218 | */ |
219 | #define isasciilower(c) (((char)(c)) >= 'a' && ((char)(c)) <= 'z') | 219 | #define isasciilower(c) (((char) (c)) >= 'a' && ((char) (c)) <= 'z') |
220 | 220 | ||
221 | 221 | ||
222 | /** | 222 | /** |
@@ -226,7 +226,7 @@ toxdigitvalue (char c) | |||
226 | * @return boolean true if character is upper case letter, | 226 | * @return boolean true if character is upper case letter, |
227 | * boolean false otherwise | 227 | * boolean false otherwise |
228 | */ | 228 | */ |
229 | #define isasciiupper(c) (((char)(c)) >= 'A' && ((char)(c)) <= 'Z') | 229 | #define isasciiupper(c) (((char) (c)) >= 'A' && ((char) (c)) <= 'Z') |
230 | 230 | ||
231 | 231 | ||
232 | /** | 232 | /** |
@@ -236,7 +236,7 @@ toxdigitvalue (char c) | |||
236 | * @return boolean true if character is letter, boolean false | 236 | * @return boolean true if character is letter, boolean false |
237 | * otherwise | 237 | * otherwise |
238 | */ | 238 | */ |
239 | #define isasciialpha(c) (isasciilower(c) || isasciiupper(c)) | 239 | #define isasciialpha(c) (isasciilower (c) || isasciiupper (c)) |
240 | 240 | ||
241 | 241 | ||
242 | /** | 242 | /** |
@@ -246,7 +246,7 @@ toxdigitvalue (char c) | |||
246 | * @return boolean true if character is decimal digit, boolean false | 246 | * @return boolean true if character is decimal digit, boolean false |
247 | * otherwise | 247 | * otherwise |
248 | */ | 248 | */ |
249 | #define isasciidigit(c) (((char)(c)) >= '0' && ((char)(c)) <= '9') | 249 | #define isasciidigit(c) (((char) (c)) >= '0' && ((char) (c)) <= '9') |
250 | 250 | ||
251 | 251 | ||
252 | /** | 252 | /** |
@@ -256,9 +256,9 @@ toxdigitvalue (char c) | |||
256 | * @return boolean true if character is hexadecimal digit, | 256 | * @return boolean true if character is hexadecimal digit, |
257 | * boolean false otherwise | 257 | * boolean false otherwise |
258 | */ | 258 | */ |
259 | #define isasciixdigit(c) (isasciidigit((c)) || \ | 259 | #define isasciixdigit(c) (isasciidigit ((c)) || \ |
260 | (((char)(c)) >= 'A' && ((char)(c)) <= 'F') || \ | 260 | (((char) (c)) >= 'A' && ((char) (c)) <= 'F') || \ |
261 | (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ) | 261 | (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ) |
262 | 262 | ||
263 | 263 | ||
264 | /** | 264 | /** |
@@ -268,7 +268,7 @@ toxdigitvalue (char c) | |||
268 | * @return boolean true if character is decimal digit or letter, | 268 | * @return boolean true if character is decimal digit or letter, |
269 | * boolean false otherwise | 269 | * boolean false otherwise |
270 | */ | 270 | */ |
271 | #define isasciialnum(c) (isasciialpha(c) || isasciidigit(c)) | 271 | #define isasciialnum(c) (isasciialpha (c) || isasciidigit (c)) |
272 | 272 | ||
273 | 273 | ||
274 | /** | 274 | /** |
@@ -280,7 +280,8 @@ toxdigitvalue (char c) | |||
280 | * @param c character to convert | 280 | * @param c character to convert |
281 | * @return converted to lower case character | 281 | * @return converted to lower case character |
282 | */ | 282 | */ |
283 | #define toasciilower(c) ((isasciiupper(c)) ? (((char)(c)) - 'A' + 'a') : ((char)(c))) | 283 | #define toasciilower(c) ((isasciiupper (c)) ? (((char) (c)) - 'A' + 'a') : \ |
284 | ((char) (c))) | ||
284 | 285 | ||
285 | 286 | ||
286 | /** | 287 | /** |
@@ -292,7 +293,8 @@ toxdigitvalue (char c) | |||
292 | * @param c character to convert | 293 | * @param c character to convert |
293 | * @return converted to upper case character | 294 | * @return converted to upper case character |
294 | */ | 295 | */ |
295 | #define toasciiupper(c) ((isasciilower(c)) ? (((char)(c)) - 'a' + 'A') : ((char)(c))) | 296 | #define toasciiupper(c) ((isasciilower (c)) ? (((char) (c)) - 'a' + 'A') : \ |
297 | ((char) (c))) | ||
296 | 298 | ||
297 | 299 | ||
298 | /** | 300 | /** |
@@ -301,7 +303,8 @@ toxdigitvalue (char c) | |||
301 | * @param c character to convert | 303 | * @param c character to convert |
302 | * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit | 304 | * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit |
303 | */ | 305 | */ |
304 | #define todigitvalue(c) (isasciidigit(c) ? (int)(((char)(c)) - '0') : (int)(-1)) | 306 | #define todigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \ |
307 | (int) (-1)) | ||
305 | 308 | ||
306 | 309 | ||
307 | /** | 310 | /** |
@@ -309,11 +312,12 @@ toxdigitvalue (char c) | |||
309 | * @param c character to convert | 312 | * @param c character to convert |
310 | * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit | 313 | * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit |
311 | */ | 314 | */ |
312 | #define toxdigitvalue(c) ( isasciidigit(c) ? (int)(((char)(c)) - '0') : \ | 315 | #define toxdigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \ |
313 | ( (((char)(c)) >= 'A' && ((char)(c)) <= 'F') ? \ | 316 | ( (((char) (c)) >= 'A' && ((char) (c)) <= 'F') ? \ |
314 | (int)(((unsigned char)(c)) - 'A' + 10) : \ | 317 | (int) (((unsigned char) (c)) - 'A' + 10) : \ |
315 | ( (((char)(c)) >= 'a' && ((char)(c)) <= 'f') ? \ | 318 | ( (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ? \ |
316 | (int)(((unsigned char)(c)) - 'a' + 10) : (int)(-1) ))) | 319 | (int) (((unsigned char) (c)) - 'a' + 10) : \ |
320 | (int) (-1) ))) | ||
317 | #endif /* !INLINE_FUNC */ | 321 | #endif /* !INLINE_FUNC */ |
318 | 322 | ||
319 | 323 | ||
@@ -326,19 +330,19 @@ toxdigitvalue (char c) | |||
326 | * @return non-zero if two strings are equal, zero otherwise. | 330 | * @return non-zero if two strings are equal, zero otherwise. |
327 | */ | 331 | */ |
328 | int | 332 | int |
329 | MHD_str_equal_caseless_ (const char * str1, | 333 | MHD_str_equal_caseless_ (const char *str1, |
330 | const char * str2) | 334 | const char *str2) |
331 | { | 335 | { |
332 | while (0 != (*str1)) | 336 | while (0 != (*str1)) |
333 | { | 337 | { |
334 | const char c1 = *str1; | 338 | const char c1 = *str1; |
335 | const char c2 = *str2; | 339 | const char c2 = *str2; |
336 | if ( (c1 != c2) && | 340 | if ( (c1 != c2) && |
337 | (toasciilower (c1) != toasciilower (c2)) ) | 341 | (toasciilower (c1) != toasciilower (c2)) ) |
338 | return 0; | 342 | return 0; |
339 | str1++; | 343 | str1++; |
340 | str2++; | 344 | str2++; |
341 | } | 345 | } |
342 | return 0 == (*str2); | 346 | return 0 == (*str2); |
343 | } | 347 | } |
344 | #endif /* ! MHD_FAVOR_SMALL_CODE */ | 348 | #endif /* ! MHD_FAVOR_SMALL_CODE */ |
@@ -356,23 +360,23 @@ MHD_str_equal_caseless_ (const char * str1, | |||
356 | * @return non-zero if two strings are equal, zero otherwise. | 360 | * @return non-zero if two strings are equal, zero otherwise. |
357 | */ | 361 | */ |
358 | int | 362 | int |
359 | MHD_str_equal_caseless_n_ (const char * const str1, | 363 | MHD_str_equal_caseless_n_ (const char *const str1, |
360 | const char * const str2, | 364 | const char *const str2, |
361 | size_t maxlen) | 365 | size_t maxlen) |
362 | { | 366 | { |
363 | size_t i; | 367 | size_t i; |
364 | 368 | ||
365 | for (i = 0; i < maxlen; ++i) | 369 | for (i = 0; i < maxlen; ++i) |
366 | { | 370 | { |
367 | const char c1 = str1[i]; | 371 | const char c1 = str1[i]; |
368 | const char c2 = str2[i]; | 372 | const char c2 = str2[i]; |
369 | if (0 == c2) | 373 | if (0 == c2) |
370 | return 0 == c1; | 374 | return 0 == c1; |
371 | if ( (c1 != c2) && | 375 | if ( (c1 != c2) && |
372 | (toasciilower (c1) != toasciilower (c2)) ) | 376 | (toasciilower (c1) != toasciilower (c2)) ) |
373 | return 0; | 377 | return 0; |
374 | } | 378 | } |
375 | return !0; | 379 | return ! 0; |
376 | } | 380 | } |
377 | 381 | ||
378 | 382 | ||
@@ -390,46 +394,49 @@ MHD_str_equal_caseless_n_ (const char * const str1, | |||
390 | * @return non-zero if two strings are equal, zero otherwise. | 394 | * @return non-zero if two strings are equal, zero otherwise. |
391 | */ | 395 | */ |
392 | bool | 396 | bool |
393 | MHD_str_has_token_caseless_ (const char * str, | 397 | MHD_str_has_token_caseless_ (const char *str, |
394 | const char * const token, | 398 | const char *const token, |
395 | size_t token_len) | 399 | size_t token_len) |
396 | { | 400 | { |
397 | if (0 == token_len) | 401 | if (0 == token_len) |
398 | return false; | 402 | return false; |
399 | 403 | ||
400 | while (0 != *str) | 404 | while (0 != *str) |
405 | { | ||
406 | size_t i; | ||
407 | /* Skip all whitespaces and empty tokens. */ | ||
408 | while (' ' == *str || '\t' == *str || ',' == *str) | ||
409 | str++; | ||
410 | |||
411 | /* Check for token match. */ | ||
412 | i = 0; | ||
413 | while (1) | ||
401 | { | 414 | { |
402 | size_t i; | 415 | const char sc = *(str++); |
403 | /* Skip all whitespaces and empty tokens. */ | 416 | const char tc = token[i++]; |
404 | while (' ' == *str || '\t' == *str || ',' == *str) str++; | 417 | |
405 | 418 | if (0 == sc) | |
406 | /* Check for token match. */ | 419 | return false; |
407 | i = 0; | 420 | if ( (sc != tc) && |
408 | while (1) | 421 | (toasciilower (sc) != toasciilower (tc)) ) |
409 | { | 422 | break; |
410 | const char sc = *(str++); | 423 | if (i >= token_len) |
411 | const char tc = token[i++]; | 424 | { |
412 | 425 | /* Check whether substring match token fully or | |
413 | if (0 == sc) | 426 | * has additional unmatched chars at tail. */ |
414 | return false; | 427 | while (' ' == *str || '\t' == *str) |
415 | if ( (sc != tc) && | 428 | str++; |
416 | (toasciilower (sc) != toasciilower (tc)) ) | 429 | /* End of (sub)string? */ |
417 | break; | 430 | if ((0 == *str) ||(',' == *str) ) |
418 | if (i >= token_len) | 431 | return true; |
419 | { | 432 | /* Unmatched chars at end of substring. */ |
420 | /* Check whether substring match token fully or | 433 | break; |
421 | * has additional unmatched chars at tail. */ | 434 | } |
422 | while (' ' == *str || '\t' == *str) str++; | ||
423 | /* End of (sub)string? */ | ||
424 | if (0 == *str || ',' == *str) | ||
425 | return true; | ||
426 | /* Unmatched chars at end of substring. */ | ||
427 | break; | ||
428 | } | ||
429 | } | ||
430 | /* Find next substring. */ | ||
431 | while (0 != *str && ',' != *str) str++; | ||
432 | } | 435 | } |
436 | /* Find next substring. */ | ||
437 | while (0 != *str && ',' != *str) | ||
438 | str++; | ||
439 | } | ||
433 | return false; | 440 | return false; |
434 | } | 441 | } |
435 | 442 | ||
@@ -450,25 +457,25 @@ size_t | |||
450 | MHD_str_to_uint64_ (const char *str, | 457 | MHD_str_to_uint64_ (const char *str, |
451 | uint64_t *out_val) | 458 | uint64_t *out_val) |
452 | { | 459 | { |
453 | const char * const start = str; | 460 | const char *const start = str; |
454 | uint64_t res; | 461 | uint64_t res; |
455 | 462 | ||
456 | if (!str || !out_val || !isasciidigit(str[0])) | 463 | if (! str || ! out_val || ! isasciidigit (str[0])) |
457 | return 0; | 464 | return 0; |
458 | 465 | ||
459 | res = 0; | 466 | res = 0; |
460 | do | 467 | do |
461 | { | 468 | { |
462 | const int digit = (unsigned char)(*str) - '0'; | 469 | const int digit = (unsigned char) (*str) - '0'; |
463 | if ( (res > (UINT64_MAX / 10)) || | 470 | if ( (res > (UINT64_MAX / 10)) || |
464 | ( (res == (UINT64_MAX / 10)) && | 471 | ( (res == (UINT64_MAX / 10)) && |
465 | ((uint64_t)digit > (UINT64_MAX % 10)) ) ) | 472 | ((uint64_t) digit > (UINT64_MAX % 10)) ) ) |
466 | return 0; | 473 | return 0; |
467 | 474 | ||
468 | res *= 10; | 475 | res *= 10; |
469 | res += digit; | 476 | res += digit; |
470 | str++; | 477 | str++; |
471 | } while (isasciidigit (*str)); | 478 | } while (isasciidigit (*str)); |
472 | 479 | ||
473 | *out_val = res; | 480 | *out_val = res; |
474 | return str - start; | 481 | return str - start; |
@@ -489,34 +496,34 @@ MHD_str_to_uint64_ (const char *str, | |||
489 | * then possible to store in uint64_t or @a out_val is NULL | 496 | * then possible to store in uint64_t or @a out_val is NULL |
490 | */ | 497 | */ |
491 | size_t | 498 | size_t |
492 | MHD_str_to_uint64_n_ (const char * str, | 499 | MHD_str_to_uint64_n_ (const char *str, |
493 | size_t maxlen, | 500 | size_t maxlen, |
494 | uint64_t *out_val) | 501 | uint64_t *out_val) |
495 | { | 502 | { |
496 | uint64_t res; | 503 | uint64_t res; |
497 | size_t i; | 504 | size_t i; |
498 | 505 | ||
499 | if (!str || !maxlen || !out_val || !isasciidigit (str[0])) | 506 | if (! str || ! maxlen || ! out_val || ! isasciidigit (str[0])) |
500 | return 0; | 507 | return 0; |
501 | 508 | ||
502 | res = 0; | 509 | res = 0; |
503 | i = 0; | 510 | i = 0; |
504 | do | 511 | do |
505 | { | 512 | { |
506 | const int digit = (unsigned char)str[i] - '0'; | 513 | const int digit = (unsigned char) str[i] - '0'; |
507 | 514 | ||
508 | if ( (res > (UINT64_MAX / 10)) || | 515 | if ( (res > (UINT64_MAX / 10)) || |
509 | ( (res == (UINT64_MAX / 10)) && | 516 | ( (res == (UINT64_MAX / 10)) && |
510 | ((uint64_t)digit > (UINT64_MAX % 10)) ) ) | 517 | ((uint64_t) digit > (UINT64_MAX % 10)) ) ) |
511 | return 0; | 518 | return 0; |
512 | 519 | ||
513 | res *= 10; | 520 | res *= 10; |
514 | res += digit; | 521 | res += digit; |
515 | i++; | 522 | i++; |
516 | } while ( (i < maxlen) && | 523 | } while ( (i < maxlen) && |
517 | isasciidigit (str[i]) ); | 524 | isasciidigit (str[i]) ); |
518 | 525 | ||
519 | *out_val= res; | 526 | *out_val = res; |
520 | return i; | 527 | return i; |
521 | } | 528 | } |
522 | 529 | ||
@@ -532,31 +539,32 @@ MHD_str_to_uint64_n_ (const char * str, | |||
532 | * then possible to store in uint32_t or @a out_val is NULL | 539 | * then possible to store in uint32_t or @a out_val is NULL |
533 | */ | 540 | */ |
534 | size_t | 541 | size_t |
535 | MHD_strx_to_uint32_ (const char * str, | 542 | MHD_strx_to_uint32_ (const char *str, |
536 | uint32_t *out_val) | 543 | uint32_t *out_val) |
537 | { | 544 | { |
538 | const char * const start = str; | 545 | const char *const start = str; |
539 | uint32_t res; | 546 | uint32_t res; |
540 | int digit; | 547 | int digit; |
541 | 548 | ||
542 | if (!str || !out_val) | 549 | if (! str || ! out_val) |
543 | return 0; | 550 | return 0; |
544 | 551 | ||
545 | res = 0; | 552 | res = 0; |
546 | digit = toxdigitvalue (*str); | 553 | digit = toxdigitvalue (*str); |
547 | while (digit >= 0) | 554 | while (digit >= 0) |
555 | { | ||
556 | if ( (res < (UINT32_MAX / 16)) || | ||
557 | ((res == (UINT32_MAX / 16)) &&( (uint32_t) digit <= (UINT32_MAX | ||
558 | % 16)) ) ) | ||
548 | { | 559 | { |
549 | if ( (res < (UINT32_MAX / 16)) || | 560 | res *= 16; |
550 | (res == (UINT32_MAX / 16) && (uint32_t)digit <= (UINT32_MAX % 16)) ) | 561 | res += digit; |
551 | { | ||
552 | res *= 16; | ||
553 | res += digit; | ||
554 | } | ||
555 | else | ||
556 | return 0; | ||
557 | str++; | ||
558 | digit = toxdigitvalue (*str); | ||
559 | } | 562 | } |
563 | else | ||
564 | return 0; | ||
565 | str++; | ||
566 | digit = toxdigitvalue (*str); | ||
567 | } | ||
560 | 568 | ||
561 | if (str - start > 0) | 569 | if (str - start > 0) |
562 | *out_val = res; | 570 | *out_val = res; |
@@ -585,21 +593,22 @@ MHD_strx_to_uint32_n_ (const char *str, | |||
585 | size_t i; | 593 | size_t i; |
586 | uint32_t res; | 594 | uint32_t res; |
587 | int digit; | 595 | int digit; |
588 | if (!str || !out_val) | 596 | if (! str || ! out_val) |
589 | return 0; | 597 | return 0; |
590 | 598 | ||
591 | res = 0; | 599 | res = 0; |
592 | i = 0; | 600 | i = 0; |
593 | while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) | 601 | while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) |
594 | { | 602 | { |
595 | if ( (res > (UINT32_MAX / 16)) || | 603 | if ( (res > (UINT32_MAX / 16)) || |
596 | (res == (UINT32_MAX / 16) && (uint32_t)digit > (UINT32_MAX % 16)) ) | 604 | ((res == (UINT32_MAX / 16)) &&( (uint32_t) digit > (UINT32_MAX |
597 | return 0; | 605 | % 16)) ) ) |
606 | return 0; | ||
598 | 607 | ||
599 | res *= 16; | 608 | res *= 16; |
600 | res += digit; | 609 | res += digit; |
601 | i++; | 610 | i++; |
602 | } | 611 | } |
603 | 612 | ||
604 | if (i) | 613 | if (i) |
605 | *out_val = res; | 614 | *out_val = res; |
@@ -621,27 +630,28 @@ size_t | |||
621 | MHD_strx_to_uint64_ (const char *str, | 630 | MHD_strx_to_uint64_ (const char *str, |
622 | uint64_t *out_val) | 631 | uint64_t *out_val) |
623 | { | 632 | { |
624 | const char * const start = str; | 633 | const char *const start = str; |
625 | uint64_t res; | 634 | uint64_t res; |
626 | int digit; | 635 | int digit; |
627 | if (!str || !out_val) | 636 | if (! str || ! out_val) |
628 | return 0; | 637 | return 0; |
629 | 638 | ||
630 | res = 0; | 639 | res = 0; |
631 | digit = toxdigitvalue (*str); | 640 | digit = toxdigitvalue (*str); |
632 | while (digit >= 0) | 641 | while (digit >= 0) |
642 | { | ||
643 | if ( (res < (UINT64_MAX / 16)) || | ||
644 | ((res == (UINT64_MAX / 16)) &&( (uint64_t) digit <= (UINT64_MAX | ||
645 | % 16)) ) ) | ||
633 | { | 646 | { |
634 | if ( (res < (UINT64_MAX / 16)) || | 647 | res *= 16; |
635 | (res == (UINT64_MAX / 16) && (uint64_t)digit <= (UINT64_MAX % 16)) ) | 648 | res += digit; |
636 | { | ||
637 | res *= 16; | ||
638 | res += digit; | ||
639 | } | ||
640 | else | ||
641 | return 0; | ||
642 | str++; | ||
643 | digit = toxdigitvalue (*str); | ||
644 | } | 649 | } |
650 | else | ||
651 | return 0; | ||
652 | str++; | ||
653 | digit = toxdigitvalue (*str); | ||
654 | } | ||
645 | 655 | ||
646 | if (str - start > 0) | 656 | if (str - start > 0) |
647 | *out_val = res; | 657 | *out_val = res; |
@@ -663,28 +673,29 @@ MHD_strx_to_uint64_ (const char *str, | |||
663 | * then possible to store in uint64_t or @a out_val is NULL | 673 | * then possible to store in uint64_t or @a out_val is NULL |
664 | */ | 674 | */ |
665 | size_t | 675 | size_t |
666 | MHD_strx_to_uint64_n_ (const char * str, | 676 | MHD_strx_to_uint64_n_ (const char *str, |
667 | size_t maxlen, | 677 | size_t maxlen, |
668 | uint64_t *out_val) | 678 | uint64_t *out_val) |
669 | { | 679 | { |
670 | size_t i; | 680 | size_t i; |
671 | uint64_t res; | 681 | uint64_t res; |
672 | int digit; | 682 | int digit; |
673 | if (!str || !out_val) | 683 | if (! str || ! out_val) |
674 | return 0; | 684 | return 0; |
675 | 685 | ||
676 | res = 0; | 686 | res = 0; |
677 | i = 0; | 687 | i = 0; |
678 | while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) | 688 | while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) |
679 | { | 689 | { |
680 | if ( (res > (UINT64_MAX / 16)) || | 690 | if ( (res > (UINT64_MAX / 16)) || |
681 | (res == (UINT64_MAX / 16) && (uint64_t)digit > (UINT64_MAX % 16)) ) | 691 | ((res == (UINT64_MAX / 16)) &&( (uint64_t) digit > (UINT64_MAX |
682 | return 0; | 692 | % 16)) ) ) |
693 | return 0; | ||
683 | 694 | ||
684 | res *= 16; | 695 | res *= 16; |
685 | res += digit; | 696 | res += digit; |
686 | i++; | 697 | i++; |
687 | } | 698 | } |
688 | 699 | ||
689 | if (i) | 700 | if (i) |
690 | *out_val = res; | 701 | *out_val = res; |
@@ -713,7 +724,7 @@ MHD_strx_to_uint64_n_ (const char * str, | |||
713 | size_t | 724 | size_t |
714 | MHD_str_to_uvalue_n_ (const char *str, | 725 | MHD_str_to_uvalue_n_ (const char *str, |
715 | size_t maxlen, | 726 | size_t maxlen, |
716 | void * out_val, | 727 | void *out_val, |
717 | size_t val_size, | 728 | size_t val_size, |
718 | uint64_t max_val, | 729 | uint64_t max_val, |
719 | int base) | 730 | int base) |
@@ -725,34 +736,34 @@ MHD_str_to_uvalue_n_ (const char *str, | |||
725 | const uint64_t max_v_mod_b = max_val % base; | 736 | const uint64_t max_v_mod_b = max_val % base; |
726 | /* 'digit->value' must be function, not macro */ | 737 | /* 'digit->value' must be function, not macro */ |
727 | int (*const dfunc)(char) = (base == 16) ? | 738 | int (*const dfunc)(char) = (base == 16) ? |
728 | toxdigitvalue : todigitvalue; | 739 | toxdigitvalue : todigitvalue; |
729 | 740 | ||
730 | if ( !str || !out_val || | 741 | if ( ! str || ! out_val || |
731 | (base != 16 && base != 10) ) | 742 | ((base != 16)&&(base != 10)) ) |
732 | return 0; | 743 | return 0; |
733 | 744 | ||
734 | res = 0; | 745 | res = 0; |
735 | i = 0; | 746 | i = 0; |
736 | while (maxlen > i && 0 <= (digit = dfunc (str[i]))) | 747 | while (maxlen > i && 0 <= (digit = dfunc (str[i]))) |
737 | { | 748 | { |
738 | if ( ((max_v_div_b) < res) || | 749 | if ( ((max_v_div_b) < res) || |
739 | ((max_v_div_b) == res && (max_v_mod_b) < (uint64_t)digit) ) | 750 | (( (max_v_div_b) == res) &&( (max_v_mod_b) < (uint64_t) digit) ) ) |
740 | return 0; | 751 | return 0; |
741 | 752 | ||
742 | res *= base; | 753 | res *= base; |
743 | res += digit; | 754 | res += digit; |
744 | i++; | 755 | i++; |
745 | } | 756 | } |
746 | 757 | ||
747 | if (i) | 758 | if (i) |
748 | { | 759 | { |
749 | if (8 == val_size) | 760 | if (8 == val_size) |
750 | *(uint64_t*)out_val = res; | 761 | *(uint64_t*) out_val = res; |
751 | else if (4 == val_size) | 762 | else if (4 == val_size) |
752 | *(uint32_t*)out_val = (uint32_t)res; | 763 | *(uint32_t*) out_val = (uint32_t) res; |
753 | else | 764 | else |
754 | return 0; | 765 | return 0; |
755 | } | 766 | } |
756 | return i; | 767 | return i; |
757 | } | 768 | } |
758 | #endif /* MHD_FAVOR_SMALL_CODE */ | 769 | #endif /* MHD_FAVOR_SMALL_CODE */ |