| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5c5022b commit 712c35d
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -394,27 +394,29 @@ write_varint(uint8_t *ptr, unsigned int val) | |||
| 394 | 394 | val >>= 6; | |
| 395 | 395 | written++; | |
| 396 | 396 | } | |
| 397 | - *ptr = val; | ||
| 397 | + *ptr = (uint8_t)val; | ||
| 398 | 398 | return written; | |
| 399 | 399 | } | |
| 400 | 400 | ||
| 401 | 401 | static inline int | |
| 402 | 402 | write_signed_varint(uint8_t *ptr, int val) | |
| 403 | 403 | { | |
| 404 | + unsigned int uval; | ||
| 404 | 405 | if (val < 0) { | |
| 405 | - val = ((-val)<<1) | 1; | ||
| 406 | + // (unsigned int)(-val) has an undefined behavior for INT_MIN | ||
| 407 | + uval = ((0 - (unsigned int)val) << 1) | 1; | ||
| 406 | 408 | } | |
| 407 | 409 | else { | |
| 408 | - val = val << 1; | ||
| 410 | + uval = (unsigned int)val << 1; | ||
| 409 | 411 | } | |
| 410 | - return write_varint(ptr, val); | ||
| 412 | + return write_varint(ptr, uval); | ||
| 411 | 413 | } | |
| 412 | 414 | ||
| 413 | 415 | static inline int | |
| 414 | 416 | write_location_entry_start(uint8_t *ptr, int code, int length) | |
| 415 | 417 | { | |
| 416 | 418 | assert((code & 15) == code); | |
| 417 | - *ptr = 128 | (code << 3) | (length - 1); | ||
| 419 | + *ptr = 128 | (uint8_t)(code << 3) | (uint8_t)(length - 1); | ||
| 418 | 420 | return 1; | |
| 419 | 421 | } | |
| 420 | 422 | ||
@@ -454,9 +456,9 @@ write_location_entry_start(uint8_t *ptr, int code, int length) | |||
| 454 | 456 | ||
| 455 | 457 | ||
| 456 | 458 | static inline uint16_t | |
| 457 | - adaptive_counter_bits(int value, int backoff) { | ||
| 458 | - return (value << ADAPTIVE_BACKOFF_BITS) | | ||
| 459 | - (backoff & ((1<<ADAPTIVE_BACKOFF_BITS)-1)); | ||
| 459 | + adaptive_counter_bits(uint16_t value, uint16_t backoff) { | ||
| 460 | + return ((value << ADAPTIVE_BACKOFF_BITS) | ||
| 461 | + | (backoff & ((1 << ADAPTIVE_BACKOFF_BITS) - 1))); | ||
| 460 | 462 | } | |
| 461 | 463 | ||
| 462 | 464 | static inline uint16_t | |
@@ -473,12 +475,12 @@ adaptive_counter_cooldown(void) { | |||
| 473 | 475 | ||
| 474 | 476 | static inline uint16_t | |
| 475 | 477 | adaptive_counter_backoff(uint16_t counter) { | |
| 476 | - unsigned int backoff = counter & ((1<<ADAPTIVE_BACKOFF_BITS)-1); | ||
| 478 | + uint16_t backoff = counter & ((1 << ADAPTIVE_BACKOFF_BITS) - 1); | ||
| 477 | 479 | backoff++; | |
| 478 | 480 | if (backoff > MAX_BACKOFF_VALUE) { | |
| 479 | 481 | backoff = MAX_BACKOFF_VALUE; | |
| 480 | 482 | } | |
| 481 | - unsigned int value = (1 << backoff) - 1; | ||
| 483 | + uint16_t value = (uint16_t)(1 << backoff) - 1; | ||
| 482 | 484 | return adaptive_counter_bits(value, backoff); | |
| 483 | 485 | } | |
| 484 | 486 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments