| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 29a5ff0 commit e005dab
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -359,27 +359,29 @@ write_varint(uint8_t *ptr, unsigned int val) | |||
| 359 | 359 | val >>= 6; | |
| 360 | 360 | written++; | |
| 361 | 361 | } | |
| 362 | - *ptr = val; | ||
| 362 | + *ptr = (uint8_t)val; | ||
| 363 | 363 | return written; | |
| 364 | 364 | } | |
| 365 | 365 | ||
| 366 | 366 | static inline int | |
| 367 | 367 | write_signed_varint(uint8_t *ptr, int val) | |
| 368 | 368 | { | |
| 369 | + unsigned int uval; | ||
| 369 | 370 | if (val < 0) { | |
| 370 | - val = ((-val)<<1) | 1; | ||
| 371 | + // (unsigned int)(-val) has an undefined behavior for INT_MIN | ||
| 372 | + uval = ((0 - (unsigned int)val) << 1) | 1; | ||
| 371 | 373 | } | |
| 372 | 374 | else { | |
| 373 | - val = val << 1; | ||
| 375 | + uval = (unsigned int)val << 1; | ||
| 374 | 376 | } | |
| 375 | - return write_varint(ptr, val); | ||
| 377 | + return write_varint(ptr, uval); | ||
| 376 | 378 | } | |
| 377 | 379 | ||
| 378 | 380 | static inline int | |
| 379 | 381 | write_location_entry_start(uint8_t *ptr, int code, int length) | |
| 380 | 382 | { | |
| 381 | 383 | assert((code & 15) == code); | |
| 382 | - *ptr = 128 | (code << 3) | (length - 1); | ||
| 384 | + *ptr = 128 | (uint8_t)(code << 3) | (uint8_t)(length - 1); | ||
| 383 | 385 | return 1; | |
| 384 | 386 | } | |
| 385 | 387 | ||
@@ -419,9 +421,9 @@ write_location_entry_start(uint8_t *ptr, int code, int length) | |||
| 419 | 421 | ||
| 420 | 422 | ||
| 421 | 423 | static inline uint16_t | |
| 422 | - adaptive_counter_bits(int value, int backoff) { | ||
| 423 | - return (value << ADAPTIVE_BACKOFF_BITS) | | ||
| 424 | - (backoff & ((1<<ADAPTIVE_BACKOFF_BITS)-1)); | ||
| 424 | + adaptive_counter_bits(uint16_t value, uint16_t backoff) { | ||
| 425 | + return ((value << ADAPTIVE_BACKOFF_BITS) | ||
| 426 | + | (backoff & ((1 << ADAPTIVE_BACKOFF_BITS) - 1))); | ||
| 425 | 427 | } | |
| 426 | 428 | ||
| 427 | 429 | static inline uint16_t | |
@@ -438,12 +440,12 @@ adaptive_counter_cooldown(void) { | |||
| 438 | 440 | ||
| 439 | 441 | static inline uint16_t | |
| 440 | 442 | adaptive_counter_backoff(uint16_t counter) { | |
| 441 | - unsigned int backoff = counter & ((1<<ADAPTIVE_BACKOFF_BITS)-1); | ||
| 443 | + uint16_t backoff = counter & ((1 << ADAPTIVE_BACKOFF_BITS) - 1); | ||
| 442 | 444 | backoff++; | |
| 443 | 445 | if (backoff > MAX_BACKOFF_VALUE) { | |
| 444 | 446 | backoff = MAX_BACKOFF_VALUE; | |
| 445 | 447 | } | |
| 446 | - unsigned int value = (1 << backoff) - 1; | ||
| 448 | + uint16_t value = (uint16_t)(1 << backoff) - 1; | ||
| 447 | 449 | return adaptive_counter_bits(value, backoff); | |
| 448 | 450 | } | |
| 449 | 451 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments