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é <[email protected]> --- tests/qtest/npcm7xx_adc-test.c | 8 ++++---- tests/qtest/npcm7xx_pwm-test.c | 14 ++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) 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); } -- 2.55.0
