mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(newlib): fixed potential overflow in usleep
If trying to usleep for 0xFFFF FFFF us the calculation of delay ticks would overflow resulting in the system not sleeping at all. Closes https://github.com/espressif/esp-idf/issues/14390
This commit is contained in:
parent
3070e0fad8
commit
f6a6ef641c
@ -194,7 +194,10 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
|
||||
|
||||
int usleep(useconds_t us)
|
||||
{
|
||||
const int us_per_tick = portTICK_PERIOD_MS * 1000;
|
||||
/* Even at max tick rate, vTaskDelay can still delay for the max of the us argument,
|
||||
we just need to make sure the tick calculation does not overflow
|
||||
*/
|
||||
const int64_t us_per_tick = portTICK_PERIOD_MS * 1000;
|
||||
if (us < us_per_tick) {
|
||||
esp_rom_delay_us((uint32_t) us);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user