From 2da7f28835da84a8426a511f5bab3cf6938cb3d1 Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Thu, 27 Aug 2026 18:21:03 +0300 Subject: [PATCH] perf: replaced sprintf with snprintf in print functions --- zh_160x_i2c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zh_160x_i2c.c b/zh_160x_i2c.c index 2a3f763..608e6e1 100644 --- a/zh_160x_i2c.c +++ b/zh_160x_i2c.c @@ -142,8 +142,8 @@ esp_err_t zh_160x_print_int(zh_160x_i2c_handle_t **handle, int num) { ZH_LOGI("160X print int started."); ZH_ERROR_CHECK(handle != NULL && *handle != NULL, ESP_ERR_INVALID_ARG, NULL, "160X print int failed. Invalid argument."); - char buffer[12]; - sprintf(buffer, "%d", num); + char buffer[16]; + snprintf(buffer, sizeof(buffer), "%d", num); ZH_ERROR_CHECK(zh_160x_print_char(handle, buffer) == ESP_OK, ESP_FAIL, NULL, "160X print int failed. PCF8574 error."); ZH_LOGI("160X print int completed successfully."); return ESP_OK; @@ -154,7 +154,7 @@ esp_err_t zh_160x_print_float(zh_160x_i2c_handle_t **handle, float num, uint8_t ZH_LOGI("160X print float started."); ZH_ERROR_CHECK(handle != NULL && *handle != NULL, ESP_ERR_INVALID_ARG, NULL, "160X print float failed. Invalid argument."); char buffer[16]; - sprintf(buffer, "%.*f", precision, num); + snprintf(buffer, sizeof(buffer), "%.*f", precision, num); ZH_ERROR_CHECK(zh_160x_print_char(handle, buffer) == ESP_OK, ESP_FAIL, NULL, "160X print float failed. PCF8574 error."); ZH_LOGI("160X print float completed successfully."); return ESP_OK;