diff mbox series

[v2,02/17] tests/qtest/npcm7xx: Replace deprecated sprintf() with g_strdup_printf()

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

Commit Message

Philippe Mathieu-Daudé Nov. 5, 2026, 12:51 p.m. UTC
Replace sprintf() by safer g_strdup_printf() 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 |  8 ++++----
 tests/qtest/npcm7xx_pwm-test.c | 14 ++++----------
 2 files changed, 8 insertions(+), 14 deletions(-)

Comments

Alex Bennée Nov. 5, 2026, 4:02 p.m. UTC | #1
Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> writes:

> Replace sprintf() by safer g_strdup_printf() 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>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Hao Wu Nov. 6, 2026, 6:52 p.m. UTC | #2
On Thu, Nov 5, 2026 at 8:02 AM Alex Bennée <alex.bennee@linaro.org> wrote:

> Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> writes:
>
> > Replace sprintf() by safer g_strdup_printf() 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>
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>
Reviewed-by: Hao Wu <wuhaotsh@google.com>

>
> --
> Alex Bennée
> Virtualisation Tech Lead @ Linaro
>
diff mbox series

Patch

diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c
index 8bc89b8a8b9a..85915d6f1243 100644
--- a/tests/qtest/npcm7xx_adc-test.c
+++ b/tests/qtest/npcm7xx_adc-test.c
@@ -135,9 +135,8 @@  static void adc_qom_set(QTestState *qts, const ADC *adc,
 static void adc_write_input(QTestState *qts, const ADC *adc,
         uint32_t index, uint32_t value)
 {
-    char name[100];
+    g_autofree char *name = g_strdup_printf("adci[%u]", index);
 
-    sprintf(name, "adci[%u]", index);
     adc_qom_set(qts, adc, name, value);
 }
 
@@ -316,10 +315,11 @@  static void test_calibrate(gconstpointer adc_p)
             adc_calculate_output(R0_INPUT, iref),
             adc_calculate_output(R1_INPUT, iref),
         };
-        char buf[100];
+        g_autofree char *buf = g_strdup_printf("-machine quanta-gsj"
+                                               " -global npcm7xx-adc.iref=%u",
+                                               iref);
         QTestState *qts;
 
-        sprintf(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..400d44f424e1 100644
--- a/tests/qtest/npcm7xx_pwm-test.c
+++ b/tests/qtest/npcm7xx_pwm-test.c
@@ -238,22 +238,16 @@  static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name)
 
 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);
+    g_autofree char *path = g_strdup_printf("/machine/soc/pwm[%d]", module_index);
+    g_autofree char *name = g_strdup_printf("freq[%d]", pwm_index);
 
     return pwm_qom_get(qts, path, name);
 }
 
 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);
+    g_autofree char *path = g_strdup_printf("/machine/soc/pwm[%d]", module_index);
+    g_autofree char *name = g_strdup_printf("duty[%d]", pwm_index);
 
     return pwm_qom_get(qts, path, name);
 }