mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_timer: Add parameter NULL checks to public API
Return ESP_ERR_INVALID_ARG if the handle is NULL, instead of crashing. As reported via forum https://esp32.com/viewtopic.php?f=13&t=11721&p=47926#p47926
This commit is contained in:
parent
367ecc2d60
commit
727ffbe908
@ -104,7 +104,7 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args,
|
||||
if (!is_initialized()) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (args->callback == NULL) {
|
||||
if (args == NULL || args->callback == NULL || out_handle == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_timer_handle_t result = (esp_timer_handle_t) calloc(1, sizeof(*result));
|
||||
@ -123,6 +123,9 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args,
|
||||
|
||||
esp_err_t IRAM_ATTR esp_timer_start_once(esp_timer_handle_t timer, uint64_t timeout_us)
|
||||
{
|
||||
if (timer == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!is_initialized() || timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
@ -136,6 +139,9 @@ esp_err_t IRAM_ATTR esp_timer_start_once(esp_timer_handle_t timer, uint64_t time
|
||||
|
||||
esp_err_t IRAM_ATTR esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period_us)
|
||||
{
|
||||
if (timer == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!is_initialized() || timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
@ -150,6 +156,9 @@ esp_err_t IRAM_ATTR esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t
|
||||
|
||||
esp_err_t IRAM_ATTR esp_timer_stop(esp_timer_handle_t timer)
|
||||
{
|
||||
if (timer == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (!is_initialized() || !timer_armed(timer)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user