diff mbox series

[2/5] tests/qtest/npcm7xx: Replace deprecated sprintf() with snprintf()

Message ID 20261104145316.18841-3-philmd@oss.qualcomm.com
State New
Headers show
Series buildsys: Replace some deprecated sprintf() | expand

Commit Message

Philippe Mathieu-Daudé Nov. 4, 2026, 2:53 p.m. UTC
Replace sprintf() by safer snprintf() to fill the QOM path and
property names. This silences when using Apple clang 17.0.0:

  ../tests/qtest/npcm7xx_adc-test.c:140:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
  ../tests/qtest/npcm7xx_adc-test.c:322:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
  ../tests/qtest/npcm7xx_pwm-test.c:244:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
  ../tests/qtest/npcm7xx_pwm-test.c:245:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
  ../tests/qtest/npcm7xx_pwm-test.c:255:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
  ../tests/qtest/npcm7xx_pwm-test.c:256:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 tests/qtest/npcm7xx_adc-test.c | 5 +++--
 tests/qtest/npcm7xx_pwm-test.c | 8 ++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

Comments

Peter Maydell Nov. 4, 2026, 3:51 p.m. UTC | #1
On Wed, 4 Nov 2026 at 14:54, Philippe Mathieu-Daudé
<philmd@oss.qualcomm.com> wrote:
>
> Replace sprintf() by safer snprintf() to fill the QOM path and
> property names. This silences when using Apple clang 17.0.0:
>
>   ../tests/qtest/npcm7xx_adc-test.c:140:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
>   ../tests/qtest/npcm7xx_adc-test.c:322:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
>   ../tests/qtest/npcm7xx_pwm-test.c:244:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
>   ../tests/qtest/npcm7xx_pwm-test.c:245:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
>   ../tests/qtest/npcm7xx_pwm-test.c:255:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
>   ../tests/qtest/npcm7xx_pwm-test.c:256:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
>  tests/qtest/npcm7xx_adc-test.c | 5 +++--
>  tests/qtest/npcm7xx_pwm-test.c | 8 ++++----
>  2 files changed, 7 insertions(+), 6 deletions(-)

g_strdup_printf() would be the preferred upgrade here for
all of these, I think. That gets rid of the fixed-sized
buffers entirely.

thanks
-- PMM
diff mbox series

Patch

diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c
index 8bc89b8a8b9a..f2fee1c32c81 100644
--- a/tests/qtest/npcm7xx_adc-test.c
+++ b/tests/qtest/npcm7xx_adc-test.c
@@ -137,7 +137,7 @@  static void adc_write_input(QTestState *qts, const ADC *adc,
 {
     char name[100];
 
-    sprintf(name, "adci[%u]", index);
+    snprintf(name, sizeof(name), "adci[%u]", index);
     adc_qom_set(qts, adc, name, value);
 }
 
@@ -319,7 +319,8 @@  static void test_calibrate(gconstpointer adc_p)
         char buf[100];
         QTestState *qts;
 
-        sprintf(buf, "-machine quanta-gsj -global npcm7xx-adc.iref=%u", iref);
+        snprintf(buf, sizeof(buf),
+                 "-machine quanta-gsj -global npcm7xx-adc.iref=%u", iref);
         qts = qtest_init(buf);
 
         /* Check the converted value is correct using the calibration value. */
diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c
index 052ea876621a..cf24ba8de346 100644
--- a/tests/qtest/npcm7xx_pwm-test.c
+++ b/tests/qtest/npcm7xx_pwm-test.c
@@ -241,8 +241,8 @@  static uint64_t pwm_get_freq(QTestState *qts, int module_index, int pwm_index)
     char path[100];
     char name[100];
 
-    sprintf(path, "/machine/soc/pwm[%d]", module_index);
-    sprintf(name, "freq[%d]", pwm_index);
+    snprintf(path, sizeof(path), "/machine/soc/pwm[%d]", module_index);
+    snprintf(name, sizeof(name), "freq[%d]", pwm_index);
 
     return pwm_qom_get(qts, path, name);
 }
@@ -252,8 +252,8 @@  static uint64_t pwm_get_duty(QTestState *qts, int module_index, int pwm_index)
     char path[100];
     char name[100];
 
-    sprintf(path, "/machine/soc/pwm[%d]", module_index);
-    sprintf(name, "duty[%d]", pwm_index);
+    snprintf(path, sizeof(path), "/machine/soc/pwm[%d]", module_index);
+    snprintf(name, sizeof(name), "duty[%d]", pwm_index);
 
     return pwm_qom_get(qts, path, name);
 }