buildsys: Replace some deprecated sprintf()
v2 cover buildsys: Replace some deprecated sprintf()
v2:
- Use g_strdup_printf (pm215)
- More replacements
Since some time now we get the build output cluttered with many deprecation warnings, it is becoming hard to notice the real ones. This series fixes few recurrent use by the --disable-tcg --enable-hvf build.
(Yes, VOF is not used on HVF x86/ARM64, I haven't
investigated why it is selected and built).
Philippe Mathieu-Daudé (17):
tests/qtest: Use qemu_hexdump_to_buffer() in qtest_memwrite() tests/qtest/npcm7xx: Replace deprecated sprintf() with
g_strdup_printf()
tests/unit/qobject: Replace deprecated sprintf() with
g_strdup_printf()
tests/unit/visitor: Replace deprecated sprintf() with snprintf() hw/ppc/vof: Replace deprecated sprintf() with snprintf() hw/usb/hcd-ohci: Replace deprecated sprintf() with snprintf() hw/riscv/platform-ref: Replace deprecated sprintf with g_strdup_printf hw/vfio/pci: Replace deprecated sprintf() with g_strdup_printf() hw/ppc/spapr: Replace deprecated sprintf() with g_strdup_printf() hw/net/eepro100: Replace deprecated sprintf() with snprintf() hw/net/rocker: Replace deprecated sprintf() with snprintf() hw/scsi: Replace deprecated sprintf() with snprintf() target/xtensa: Replace deprecated sprintf() with snprintf() target/m68k: Replace deprecated sprintf() with snprintf() target/rx: Replace deprecated sprintf() with snprintf()
libdecnumber: Replace deprecated sprintf() with snprintf() qga/vss-win32: Replace deprecated sprintf() by StrCatBuffA()
hw/net/eepro100.c | 2 +- hw/net/rocker/rocker.c | 24 ++++++------ hw/ppc/spapr.c | 3 +- hw/ppc/vof.c | 2 +- hw/riscv/server_platform_ref.c | 11 +++--- hw/scsi/scsi-generic.c | 2 +- hw/usb/hcd-ohci.c | 2 +- hw/vfio/pci.c | 7 ++-- libdecnumber/dpd/decimal128.c | 4 +- libdecnumber/dpd/decimal32.c | 4 +- libdecnumber/dpd/decimal64.c | 4 +- target/m68k/translate.c | 6 +-- target/rx/disas.c | 2 +- target/xtensa/xtensa-isa.c | 50 +++++++++++++++--------- tests/qtest/libqtest.c | 6 +-- tests/qtest/npcm7xx_adc-test.c | 8 ++-- tests/qtest/npcm7xx_pwm-test.c | 14 ++----- tests/unit/test-qobject-input-visitor.c | 4 +- tests/unit/test-qobject-output-visitor.c | 3 +- tests/unit/test-visitor-serialization.c | 21 ++++++---- qga/vss-win32/install.cpp | 17 +++++--- 21 files changed, 102 insertions(+), 94 deletions(-)
Signature · 1 line
2.55.0
PATCH v2 1/17 tests/qtest: Use qemu_hexdump_to_buffer() in qtest_memwrite()
Replace sprintf("%02x) by equivalent qemu_hexdump_to_buffer() helper and silent when using Apple clang 17.0.0:
../tests/qtest/libqtest.c:1522:9: warning: 'sprintf' is deprecated:
This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
--- tests/qtest/libqtest.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
tests/qtest/libqtest.c +1 -5
@@ -1509,7 +1509,6 @@ void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size)void qtest_memwrite (QTestState *s,uint64_t addr,const void *data,size_t size) {const uint8_t *ptr = data; -size_t i;char *enc;if (!size) {
@@ -1517,10 +1516,7 @@ void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size) } enc =g_malloc (2 * size +1 ); - -for (i =0 ; i < size; i++) { -sprintf (&enc[i *2 ],"%02x" , ptr[i]); - } +qemu_hexdump_to_buffer (enc,2 * size +1 , ptr, size);qtest_sendf (s,"write 0x%" PRIx64" 0x%zx 0x%s\n" , addr, size, enc);qtest_rsp (s);
Signature · 1 line
2.55.0
Re: [PATCH v2 01/17] tests/qtest: Use qemu_hexdump_to_buffer() in qtest_memwrite()
Quoted 11 lines · Philippe Mathieu-Daudé
Replace
sprintf("%02x)by equivalentqemu_hexdump_to_buffer()helper and silent when using Apple clang 17.0.0:
../tests/qtest/libqtest.c:1522:9: warning: 'sprintf' is deprecated:
This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]Signed-off-by Philippe Mathieu-Daudé <[email protected]>
thanks
-- PMM
PATCH v2 2/17 tests/qtest/npcm7xx: Replace deprecated sprintf() with g_strdup_printf()
In reply to Philippe Mathieu-Daudé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]
--- tests/qtest/npcm7xx_adc-test.c | 8 ++++---- tests/qtest/npcm7xx_pwm-test.c | 14 ++++---------- 2 files changed, 8 insertions(+), 14 deletions(-)
tests/qtest/npcm7xx_adc-test.c +4 -4
@@ -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. */
tests/qtest/npcm7xx_pwm-test.c +4 -10
@@ -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); }
Signature · 1 line
2.55.0
Re: [PATCH v2 02/17] tests/qtest/npcm7xx: Replace deprecated sprintf() with g_strdup_printf()
Quoted 11 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_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]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Hao Wu
Reviewed-byRe: [PATCH v2 02/17] tests/qtest/npcm7xx: Replace deprecated sprintf() with g_strdup_printf()
Quoted 13 lines · Alex Bennée
Quoted 4 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_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' isdeprecated [-Wdeprecated-declarations]
Quoted 1 line
../tests/qtest/npcm7xx_adc-test.c:322:9: warning: 'sprintf' isdeprecated [-Wdeprecated-declarations]
Quoted 1 line
../tests/qtest/npcm7xx_pwm-test.c:244:5: warning: 'sprintf' isdeprecated [-Wdeprecated-declarations]
Quoted 1 line
../tests/qtest/npcm7xx_pwm-test.c:245:5: warning: 'sprintf' isdeprecated [-Wdeprecated-declarations]
Quoted 9 lines
Quoted 1 line
../tests/qtest/npcm7xx_pwm-test.c:255:5: warning: 'sprintf' isdeprecated [-Wdeprecated-declarations]
Quoted 1 line
../tests/qtest/npcm7xx_pwm-test.c:256:5: warning: 'sprintf' isdeprecated [-Wdeprecated-declarations]
Quoted 2 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Alex Bennée <[email protected]>
Quoted 5 lines
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
PATCH v2 3/17 tests/unit/qobject: Replace deprecated sprintf() with g_strdup_printf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer g_strdup_printf() to avoid when using Apple clang 17.0.0 on macOS ARM64:
../tests/unit/test-qobject-output-visitor.c:598:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations] ../tests/unit/test-qobject-input-visitor.c:600:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
--- tests/unit/test-qobject-input-visitor.c | 4 +--- tests/unit/test-qobject-output-visitor.c | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-)
tests/unit/test-qobject-input-visitor.c +1 -3
@@ -595,9 +595,7 @@ static void test_visitor_in_list_struct(TestInputVisitorData *data, i =0 ;for (str_list = arrs->string; str_list; str_list = str_list->next) { -char expected[32 ]; - -sprintf (expected,"%d" , i); + g_autofree char *expected = g_strdup_printf("%d", i); g_assert_cmpstr(str_list->value, ==, expected); i++; }
tests/unit/test-qobject-output-visitor.c +1 -2
@@ -592,10 +592,9 @@ static void test_visitor_out_list_struct(TestOutputVisitorData *data, i =0 ; QLIST_FOREACH_ENTRY(qlist, e) {QString *qvalue =qobject_to (QString,qlist_entry_obj (e)); -char expected[32 ]; + g_autofree char *expected = g_strdup_printf("%d", i);g_assert (qvalue); -sprintf (expected,"%d" , i); g_assert_cmpstr(qstring_get_str(qvalue), ==, expected); i++; }
Signature · 1 line
2.55.0
Re: [PATCH v2 03/17] tests/unit/qobject: Replace deprecated sprintf() with g_strdup_printf()
Quoted 7 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_strdup_printf()to avoid when using Apple clang 17.0.0 on macOS ARM64:
../tests/unit/test-qobject-output-visitor.c:598:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]../tests/unit/test-qobject-input-visitor.c:600:9: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH v2 4/17 tests/unit/visitor: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to avoid when using Apple clang 17.0.0 on macOS ARM64:
../tests/unit/test-visitor-serialization.c:1031:5: warning: 'sprintf' is deprecated [-Wdeprecated-declarations] ../tests/unit/test-visitor-serialization.c:1035:13: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
...
Use pstrcpy() when no formatting is needed.
--- tests/unit/test-visitor-serialization.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
tests/unit/test-visitor-serialization.c +13 -8
@@ -14,6 +14,7 @@#include "qemu/osdep.h" #include <float.h> +#include "qemu/cutils.h" #include "test-qapi-visit.h" #include "qapi/error.h" #include "qobject/qjson.h"
@@ -1028,12 +1029,13 @@ static void add_visitor_type(const SerializeOps *ops)TestArgs *args;int i =0 ; -sprintf (testname_prefix,"/visitor/serialization/%s" , ops->type); +snprintf (testname_prefix,sizeof (testname_prefix), +"/visitor/serialization/%s" , ops->type);if (ops->caps &VCAP_PRIMITIVES ) {while (pt_values[i].type !=PTYPE_EOL ) { -sprintf (testname,"%s/primitives/%s" , testname_prefix, - pt_values[i].description); +snprintf (testname,sizeof (testname),"%s/primitives/%s" , + testname_prefix, pt_values[i].description); args =g_malloc0 (sizeof (*args)); args->ops = ops; args->test_data = &pt_values[i];
@@ -1043,13 +1045,15 @@ static void add_visitor_type(const SerializeOps *ops) }if (ops->caps &VCAP_STRUCTURES ) { -sprintf (testname,"%s/struct" , testname_prefix); +pstrcpy (testname,sizeof (testname), testname_prefix); +pstrcat (testname,sizeof (testname),"/struct" ); args =g_malloc0 (sizeof (*args)); args->ops = ops; args->test_data =NULL ;g_test_add_data_func (testname, args, test_struct); -sprintf (testname,"%s/nested_struct" , testname_prefix); +pstrcpy (testname,sizeof (testname), testname_prefix); +pstrcat (testname,sizeof (testname),"/nested_struct" ); args =g_malloc0 (sizeof (*args)); args->ops = ops; args->test_data =NULL ;
@@ -1057,7 +1061,8 @@ static void add_visitor_type(const SerializeOps *ops) }if (ops->caps &VCAP_LISTS ) { -sprintf (testname,"%s/nested_struct_list" , testname_prefix); +pstrcpy (testname,sizeof (testname), testname_prefix); +pstrcat (testname,sizeof (testname),"/nested_struct_list" ); args =g_malloc0 (sizeof (*args)); args->ops = ops; args->test_data =NULL ;
@@ -1067,8 +1072,8 @@ static void add_visitor_type(const SerializeOps *ops)if (ops->caps &VCAP_PRIMITIVE_LISTS ) { i =0 ;while (pt_values[i].type !=PTYPE_EOL ) { -sprintf (testname,"%s/primitive_list/%s" , testname_prefix, - pt_values[i].description); +snprintf (testname,sizeof (testname),"%s/primitive_list/%s" , + testname_prefix, pt_values[i].description); args =g_malloc0 (sizeof (*args)); args->ops = ops; args->test_data = &pt_values[i];
Signature · 1 line
2.55.0
PATCH v2 5/17 hw/ppc/vof: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to avoid when using Apple clang 17.0.0 on macOS ARM64:
../hw/ppc/vof.c:104:14: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
--- hw/ppc/vof.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/vof.c +1 -1
@@ -101,7 +101,7 @@ static void prop_format(char *tval, int tlen, const void *prop, int len)strcat (t," " ); ++t; } - t +=sprintf (t,"%02X" , *c &0xFF ); + t +=snprintf (t, tval + tlen - t,"%02X" , *c &0xFF ); } }
Signature · 1 line
2.55.0
PATCH v2 6/17 hw/usb/hcd-ohci: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to avoid when using Apple clang 17.0.0 on macOS ARM64:
../hw/usb/hcd-ohci.c:875:14: warning: 'sprintf' is deprecated [-Wdeprecated-declarations]
--- hw/usb/hcd-ohci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/hcd-ohci.c +1 -1
@@ -872,7 +872,7 @@ static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len)break ; } - p +=sprintf (p," %.2x" , buf[i]); + p +=snprintf (p, tmp +sizeof (tmp) - p," %.2x" , buf[i]); } }
Signature · 1 line
2.55.0
PATCH v2 7/17 hw/riscv/platform-ref: Replace deprecated sprintf with g_strdup_printf
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer g_strdup_printf() to format the AIA guest count / description, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- hw/riscv/server_platform_ref.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/riscv/server_platform_ref.c +5 -6
@@ -668,10 +668,8 @@ static void rvserver_ref_machine_instance_finalize(Object *obj)static char *rvserver_ref_get_aia_guests (Object *obj,Error **errp) {RISCVServerRefMachineState *s =RISCV_SERVER_REF_MACHINE (obj); -char val[32 ]; -sprintf (val,"%d" , s->aia_guests); -return g_strdup (val); +return g_strdup_printf ("%d" , s->aia_guests); } static void rvserver_ref_set_aia_guests(Object *obj, const char *val,
@@ -716,7 +714,10 @@ static void rvserver_machine_device_plug_cb(const HotplugHandler *hotplug_dev,static void rvserver_ref_machine_class_init (ObjectClass *oc,const void *data) { -char str[128 ]; + g_autofree char *str = g_strdup_printf("Set number of guest MMIO pages" +" for AIA IMSIC. Valid value should" +" be between 0 and %d." , +RVSERVER_IRQCHIP_MAX_GUESTS );MachineClass *mc =MACHINE_CLASS (oc);HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);static const char *const valid_cpu_types[] = {
@@ -743,8 +744,6 @@ static void rvserver_ref_machine_class_init(ObjectClass *oc, const void *data)object_class_property_add_str (oc,"aia-guests" , rvserver_ref_get_aia_guests, rvserver_ref_set_aia_guests); -sprintf (str,"Set number of guest MMIO pages for AIA IMSIC. Valid value " -"should be between 0 and %d." ,RVSERVER_IRQCHIP_MAX_GUESTS );object_class_property_set_description (oc,"aia-guests" , str);assert (!mc->get_hotplug_handler);
Signature · 1 line
2.55.0
Re: [PATCH v2 07/17] hw/riscv/platform-ref: Replace deprecated sprintf with g_strdup_printf
Quoted 5 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_strdup_printf()to format the AIA guest count / description, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
<snip>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH v2 07/17] hw/riscv/platform-ref: Replace deprecated sprintf with g_strdup_printf
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_strdup_printf()to format the AIA guest count / description, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 52 lines
---
hw/riscv/server_platform_ref.c | 11 +++++------1 file changed, 5 insertions(+), 6 deletions(-)hw/riscv/server_platform_ref.c +0
-1@@ -668,10 +668,8 @@ static void rvserver_ref_machine_instance_finalize(Object *obj) static char *rvserver_ref_get_aia_guests(Object *obj, Error **errp) { RISCVServerRefMachineState *s = RISCV_SERVER_REF_MACHINE(obj); - char val[32];
-sprintf(val, "%d", s->aia_guests);
- returng_strdup(val);
+ returng_strdup_printf("%d", s->aia_guests);
}
static void rvserver_ref_set_aia_guests(Object *obj, const char *val,hw/riscv/server_platform_ref.c +0
-0@@ -716,7 +714,10 @@ static void rvserver_machine_device_plug_cb(const HotplugHandler *hotplug_dev,
static voidrvserver_ref_machine_class_init(ObjectClass *oc, const void *data)
{
- char str[128];
+g_autofreechar *str = g_strdup_printf("Set number of guest MMIO pages"
+ " for AIA IMSIC. Valid value should"
+ " be between 0 and %d.", +RVSERVER_IRQCHIP_MAX_GUESTS);
MachineClass *mc =MACHINE_CLASS(oc); HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS(oc); static const char * const valid_cpu_types[] = {hw/riscv/server_platform_ref.c +0
-1@@ -743,8 +744,6 @@ static void rvserver_ref_machine_class_init(ObjectClass *oc, const void *data) object_class_property_add_str(oc, "aia-guests", rvserver_ref_get_aia_guests, rvserver_ref_set_aia_guests); - sprintf(str, "Set number of guest MMIO pages for AIA IMSIC.Valid value "
- "should be between 0 and %d.",RVSERVER_IRQCHIP_MAX_GUESTS);object_class_property_set_description(oc, "aia-guests", str);
assert(!mc->get_hotplug_handler);
PATCH v2 8/17 hw/vfio/pci: Replace deprecated sprintf() with g_strdup_printf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer g_strdup_printf() to format the host address, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- hw/vfio/pci.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/vfio/pci.c +3 -4
@@ -2857,10 +2857,9 @@ void vfio_pci_post_reset(VFIOPCIDevice *vdev)bool vfio_pci_host_match (PCIHostDeviceAddress *addr,const char *name) { -char tmp[36 ]; - -sprintf (tmp,"%04x:%02x:%02x.%1x" , addr->domain, - addr->bus, addr->slot, addr->function); + g_autofree char *tmp = g_strdup_printf("%04x:%02x:%02x.%1x", + addr->domain, addr->bus, addr->slot, + addr->function);return (strcmp (tmp, name) ==0 ); }
Signature · 1 line
2.55.0
Re: [PATCH v2 08/17] hw/vfio/pci: Replace deprecated sprintf() with g_strdup_printf()
Quoted 17 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_strdup_printf()to format the host address, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/vfio/pci.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/vfio/pci.c +0
-0@@ -2857,10 +2857,9 @@ void vfio_pci_post_reset(VFIOPCIDevice *vdev)bool vfio_pci_host_match (PCIHostDeviceAddress *addr,const char *name) {
hw/vfio/pci.c void vfio_pci_post_reset(VFIOPCIDevice *vdev) · line 2865
Quoted 10 lines
hw/vfio/pci.c +3
-4-char tmp[36 ]; - -sprintf (tmp,"%04x:%02x:%02x.%1x" , addr->domain, - addr->bus, addr->slot, addr->function); + g_autofree char *tmp = g_strdup_printf("%04x:%02x:%02x.%1x", + addr->domain, addr->bus, addr->slot, + addr->function);return (strcmp (tmp, name) ==0 ); }
Thanks,
C.
PATCH v2 9/17 hw/ppc/spapr: Replace deprecated sprintf() with g_strdup_printf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer g_strdup_printf() to format the node name, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- hw/ppc/spapr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/spapr.c +1 -2
@@ -352,14 +352,13 @@ static void add_str(GString *s, const gchar *s1)static int spapr_dt_memory_node (SpaprMachineState *spapr,void *fdt,int nodeid,hwaddr start,hwaddr size) { -char mem_name[32 ]; + g_autofree char *mem_name = g_strdup_printf("memory@%" HWADDR_PRIx, start);uint64_t mem_reg_property[2 ];int off; mem_reg_property[0 ] =cpu_to_be64 (start); mem_reg_property[1 ] =cpu_to_be64 (size); -sprintf (mem_name,"memory@%" HWADDR_PRIx, start); off =fdt_add_subnode (fdt,0 , mem_name);_FDT (off);_FDT ((fdt_setprop_string (fdt, off,"device_type" ,"memory" )));
Signature · 1 line
2.55.0
Re: [PATCH v2 09/17] hw/ppc/spapr: Replace deprecated sprintf() with g_strdup_printf()
Quoted 16 lines · Philippe Mathieu-Daudé
Replace
sprintf()by saferg_strdup_printf()to format the node name, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/ppc/spapr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/ppc/spapr.c +0
-0@@ -352,14 +352,13 @@ static void add_str(GString *s, const gchar *s1)static int spapr_dt_memory_node (SpaprMachineState *spapr,void *fdt,int nodeid,hwaddr start,hwaddr size)
hw/ppc/spapr.c static void add_str(GString *s, const gchar *s1) · line 362
Quoted 10 lines
hw/ppc/spapr.c +1
-2{ -char mem_name[32 ]; + g_autofree char *mem_name = g_strdup_printf("memory@%" HWADDR_PRIx, start);uint64_t mem_reg_property[2 ];int off; mem_reg_property[0 ] =cpu_to_be64 (start); mem_reg_property[1 ] =cpu_to_be64 (size); -sprintf (mem_name,"memory@%" HWADDR_PRIx, start);
hw/ppc/spapr.c static void add_str(GString *s, const gchar *s1) · line 362
Quoted 1 line
hw/ppc/spapr.c +0
-0off =fdt_add_subnode (fdt,0 , mem_name);
fun fact, ppc seems to be one of the arches that mixes fdt_add_subnode with qemu_fdt_add_subnode.
Quoted 2 lines
hw/ppc/spapr.c +0
-0_FDT (off);_FDT ((fdt_setprop_string (fdt, off,"device_type" ,"memory" )));
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH v2 10/17 hw/net/eepro100: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format debug dump silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- hw/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/eepro100.c +1 -1
@@ -369,7 +369,7 @@ static const char *nic_dump(const uint8_t * buf, unsigned size) size =16 ; }while (size-- >0 ) { - p +=sprintf (p," %02x" , *buf++); + p +=snprintf (p,sizeof (dump) - (p - dump)," %02x" , *buf++); }return dump; }
Signature · 1 line
2.55.0
Re: [PATCH v2 10/17] hw/net/eepro100: Replace deprecated sprintf() with snprintf()
Quoted 14 lines · Philippe Mathieu-Daudé
Replace
sprintf()by safersnprintf()to format debug dump silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/net/eepro100.c +0
-0
hw/net/eepro100.c static const char *nic_dump(const uint8_t * buf, unsigned size) · line 372
Quoted 5 lines
hw/net/eepro100.c +1
-1@@ -369,7 +369,7 @@ static const char *nic_dump(const uint8_t * buf, unsigned size) size =16 ; }while (size-- >0 ) { - p +=sprintf (p," %02x" , *buf++); + p +=snprintf (p,sizeof (dump) - (p - dump)," %02x" , *buf++);
I was going to say the whole function could be re-done to avoid the static buffer in nic_dump but that took me to TRACE and then missing() and I realised you probably didn't sign up to modernise the eepro100 emulation ;-)
Quoted 3 lines
hw/net/eepro100.c +0
-0}return dump; }
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH v2 11/17 hw/net/rocker: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format debug register, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
Use pstrcpy() when no formatting is needed.
--- hw/net/rocker/rocker.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
hw/net/rocker/rocker.c +12 -12
@@ -910,40 +910,40 @@ static const char *rocker_reg_name(void *opaque, hwaddr addr)switch (index) {case 0 : -sprintf (ring_name,"cmd" ); +pstrcpy (ring_name,sizeof (ring_name),"cmd" );break ;case 1 : -sprintf (ring_name,"event" ); +pstrcpy (ring_name,sizeof (ring_name),"event" );break ;default : -sprintf (ring_name,"%s-%d" , index %2 ?"rx" :"tx" , - (index -2 ) /2 ); +snprintf (ring_name,sizeof (ring_name),"%s-%d" , + index %2 ?"rx" :"tx" , (index -2 ) /2 ); }switch (offset) {case ROCKER_DMA_DESC_ADDR_OFFSET : -sprintf (buf,"Ring[%s] ADDR" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] ADDR" , ring_name);return buf;case ROCKER_DMA_DESC_ADDR_OFFSET +4 : -sprintf (buf,"Ring[%s] ADDR+4" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] ADDR+4" , ring_name);return buf;case ROCKER_DMA_DESC_SIZE_OFFSET : -sprintf (buf,"Ring[%s] SIZE" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] SIZE" , ring_name);return buf;case ROCKER_DMA_DESC_HEAD_OFFSET : -sprintf (buf,"Ring[%s] HEAD" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] HEAD" , ring_name);return buf;case ROCKER_DMA_DESC_TAIL_OFFSET : -sprintf (buf,"Ring[%s] TAIL" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] TAIL" , ring_name);return buf;case ROCKER_DMA_DESC_CTRL_OFFSET : -sprintf (buf,"Ring[%s] CTRL" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] CTRL" , ring_name);return buf;case ROCKER_DMA_DESC_CREDITS_OFFSET : -sprintf (buf,"Ring[%s] CREDITS" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] CREDITS" , ring_name);return buf;default : -sprintf (buf,"Ring[%s] ???" , ring_name); +snprintf (buf,sizeof (buf),"Ring[%s] ???" , ring_name);return buf; } }else {
Signature · 1 line
2.55.0
PATCH v2 12/17 hw/scsi: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format command trace, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- hw/scsi/scsi-generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/scsi-generic.c +1 -1
@@ -863,7 +863,7 @@ static void scsi_generic_command_dump(uint8_t *cmd, int len) line_buffer =g_malloc (len *5 +1 );for (i =0 , p = line_buffer; i < len; i++) { - p +=sprintf (p," 0x%02x" , cmd[i]); + p +=snprintf (p, (len - i) *5 +1 ," 0x%02x" , cmd[i]); }trace_scsi_generic_send_command (line_buffer);
Signature · 1 line
2.55.0
PATCH v2 13/17 target/xtensa: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format ISA error message, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- target/xtensa/xtensa-isa.c | 50 +++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 19 deletions(-)
target/xtensa/xtensa-isa.c +31 -19
@@ -519,7 +519,8 @@ xtensa_format xtensa_format_lookup(xtensa_isa isa, const char *fmtname) } xtisa_errno = xtensa_isa_bad_format; -sprintf (xtisa_error_msg,"format \"%s\" not recognized" , fmtname); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"format \"%s\" not recognized" , fmtname);return XTENSA_UNDEFINED ; }
@@ -646,7 +647,8 @@ xtensa_opcode xtensa_opcode_lookup(xtensa_isa isa, const char *opname)if (!result) { xtisa_errno = xtensa_isa_bad_opcode; -sprintf (xtisa_error_msg,"opcode \"%s\" not recognized" , opname); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"opcode \"%s\" not recognized" , opname);return XTENSA_UNDEFINED ; }
@@ -692,7 +694,7 @@ int xtensa_opcode_encode(xtensa_isa isa, xtensa_format fmt, int slot, encode_fn = intisa->opcodes[opc].encode_fns[slot_id];if (!encode_fn) { xtisa_errno = xtensa_isa_wrong_slot; -sprintf (xtisa_error_msg, +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg),"opcode \"%s\" is not allowed in slot %d of format \"%s\"" , intisa->opcodes[opc].name, slot, intisa->formats[fmt].name);return -1 ;
@@ -809,7 +811,8 @@ xtensa_funcUnit_use *xtensa_opcode_funcUnit_use(xtensa_isa isa,CHECK_OPCODE (intisa, opc,NULL );if (u <0 || u >= intisa->opcodes[opc].num_funcUnit_uses) { xtisa_errno = xtensa_isa_bad_funcUnit; -sprintf (xtisa_error_msg,"invalid functional unit use number (%d); " +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"invalid functional unit use number (%d); " "opcode \"%s\" has %d" , u, intisa->opcodes[opc].name, intisa->opcodes[opc].num_funcUnit_uses);return NULL ;
@@ -825,7 +828,8 @@ xtensa_funcUnit_use *xtensa_opcode_funcUnit_use(xtensa_isa isa, do { \ if ((OPND) < 0 || (OPND) >= (ICLASS)->num_operands) { \ xtisa_errno = xtensa_isa_bad_operand; \ - sprintf(xtisa_error_msg, "invalid operand number (%d); " \ + snprintf(xtisa_error_msg, sizeof(xtisa_error_msg), \ + "invalid operand number (%d); " \ "opcode \"%s\" has %d operands", (OPND), \ (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_operands); \ return ERRVAL; \
@@ -938,7 +942,7 @@ int xtensa_operand_get_field(xtensa_isa isa, xtensa_opcode opc, int opnd, get_fn = intisa->slots[slot_id].get_field_fns[intop->field_id];if (!get_fn) { xtisa_errno = xtensa_isa_wrong_slot; -sprintf (xtisa_error_msg, +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg),"operand \"%s\" does not exist in slot %d of format \"%s\"" , intop->name, slot, intisa->formats[fmt].name);return -1 ;
@@ -974,7 +978,7 @@ int xtensa_operand_set_field(xtensa_isa isa, xtensa_opcode opc, int opnd, set_fn = intisa->slots[slot_id].set_field_fns[intop->field_id];if (!set_fn) { xtisa_errno = xtensa_isa_wrong_slot; -sprintf (xtisa_error_msg, +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg),"operand \"%s\" does not exist in slot %d of format \"%s\"" , intop->name, slot, intisa->formats[fmt].name);return -1 ;
@@ -1050,7 +1054,8 @@ int xtensa_operand_encode(xtensa_isa isa, xtensa_opcode opc, int opnd, (test_val = *valp, (*intop->decode)(&test_val)) || test_val != orig_val) { xtisa_errno = xtensa_isa_bad_value; -sprintf (xtisa_error_msg,"cannot encode operand value 0x%08x" , *valp); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"cannot encode operand value 0x%08x" , *valp);return -1 ; }
@@ -1076,7 +1081,8 @@ int xtensa_operand_decode(xtensa_isa isa, xtensa_opcode opc, int opnd,if ((*intop->decode)(valp)) { xtisa_errno = xtensa_isa_bad_value; -sprintf (xtisa_error_msg,"cannot decode operand value 0x%08x" , *valp); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"cannot decode operand value 0x%08x" , *valp);return -1 ; }return 0 ;
@@ -1186,7 +1192,7 @@ int xtensa_operand_do_reloc(xtensa_isa isa, xtensa_opcode opc, int opnd,if ((*intop->do_reloc)(valp, pc)) { xtisa_errno = xtensa_isa_bad_value; -sprintf (xtisa_error_msg, +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg),"do_reloc failed for value 0x%08x at PC 0x%08x" , *valp, pc);return -1 ; }
@@ -1218,7 +1224,7 @@ int xtensa_operand_undo_reloc(xtensa_isa isa, xtensa_opcode opc, int opnd,if ((*intop->undo_reloc)(valp, pc)) { xtisa_errno = xtensa_isa_bad_value; -sprintf (xtisa_error_msg, +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg),"undo_reloc failed for value 0x%08x at PC 0x%08x" , *valp, pc);return -1 ; }
@@ -1234,7 +1240,8 @@ int xtensa_operand_undo_reloc(xtensa_isa isa, xtensa_opcode opc, int opnd, do { \ if ((STOP) < 0 || (STOP) >= (ICLASS)->num_stateOperands) { \ xtisa_errno = xtensa_isa_bad_operand; \ - sprintf(xtisa_error_msg, "invalid state operand number (%d); " \ + snprintf(xtisa_error_msg, sizeof(xtisa_error_msg), \ + "invalid state operand number (%d); " \ "opcode \"%s\" has %d state operands", (STOP), \ (INTISA)->opcodes[(OPC)].name, \ (ICLASS)->num_stateOperands); \
@@ -1279,7 +1286,7 @@ char xtensa_stateOperand_inout(xtensa_isa isa, xtensa_opcode opc, int stOp) do { \ if ((IFOP) < 0 || (IFOP) >= (ICLASS)->num_interfaceOperands) { \ xtisa_errno = xtensa_isa_bad_operand; \ - sprintf(xtisa_error_msg, \ + snprintf(xtisa_error_msg, sizeof(xtisa_error_msg), \ "invalid interface operand number (%d); " \ "opcode \"%s\" has %d interface operands", (IFOP), \ (INTISA)->opcodes[(OPC)].name, \
@@ -1337,7 +1344,8 @@ xtensa_regfile xtensa_regfile_lookup(xtensa_isa isa, const char *name) } xtisa_errno = xtensa_isa_bad_regfile; -sprintf (xtisa_error_msg,"regfile \"%s\" not recognized" , name); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"regfile \"%s\" not recognized" , name);return XTENSA_UNDEFINED ; }
@@ -1369,7 +1377,8 @@ xtensa_regfile xtensa_regfile_lookup_shortname(xtensa_isa isa, } xtisa_errno = xtensa_isa_bad_regfile; -sprintf (xtisa_error_msg,"regfile shortname \"%s\" not recognized" , +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"regfile shortname \"%s\" not recognized" , shortname);return XTENSA_UNDEFINED ; }
@@ -1453,7 +1462,8 @@ xtensa_state xtensa_state_lookup(xtensa_isa isa, const char *name)if (!result) { xtisa_errno = xtensa_isa_bad_state; -sprintf (xtisa_error_msg,"state \"%s\" not recognized" , name); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"state \"%s\" not recognized" , name);return XTENSA_UNDEFINED ; }
@@ -1555,7 +1565,8 @@ xtensa_sysreg xtensa_sysreg_lookup_name(xtensa_isa isa, const char *name)if (!result) { xtisa_errno = xtensa_isa_bad_sysreg; -sprintf (xtisa_error_msg,"sysreg \"%s\" not recognized" , name); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"sysreg \"%s\" not recognized" , name);return XTENSA_UNDEFINED ; }
@@ -1626,7 +1637,8 @@ xtensa_interface xtensa_interface_lookup(xtensa_isa isa, const char *ifname)if (!result) { xtisa_errno = xtensa_isa_bad_interface; -sprintf (xtisa_error_msg,"interface \"%s\" not recognized" , ifname); +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg), +"interface \"%s\" not recognized" , ifname);return XTENSA_UNDEFINED ; }
@@ -1716,7 +1728,7 @@ xtensa_funcUnit xtensa_funcUnit_lookup(xtensa_isa isa, const char *fname)if (!result) { xtisa_errno = xtensa_isa_bad_funcUnit; -sprintf (xtisa_error_msg, +snprintf (xtisa_error_msg,sizeof (xtisa_error_msg),"functional unit \"%s\" not recognized" , fname);return XTENSA_UNDEFINED ; }
Signature · 1 line
2.55.0
Re: [PATCH v2 13/17] target/xtensa: Replace deprecated sprintf() with snprintf()
Quoted 9 lines · Philippe Mathieu-Daudé
Replace
sprintf()by safersnprintf()to format ISA error message, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/xtensa/xtensa-isa.c | 50 +++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 19 deletions(-)
Signature · 2 lines
Thanks. -- Max
PATCH v2 14/17 target/m68k: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format register name, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- target/m68k/translate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/m68k/translate.c +3 -3
@@ -77,17 +77,17 @@ void m68k_tcg_init(void) p = cpu_reg_names;for (i =0 ; i <8 ; i++) { -sprintf (p,"D%d" , i); +snprintf (p,3 ,"D%d" , i); cpu_dregs[i] =tcg_global_mem_new (tcg_env, offsetof(CPUM68KState, dregs[i]), p); p +=3 ; -sprintf (p,"A%d" , i); +snprintf (p,3 ,"A%d" , i); cpu_aregs[i] =tcg_global_mem_new (tcg_env, offsetof(CPUM68KState, aregs[i]), p); p +=3 ; }for (i =0 ; i <4 ; i++) { -sprintf (p,"ACC%d" , i); +snprintf (p,5 ,"ACC%d" , i); cpu_macc[i] =tcg_global_mem_new_i64 (tcg_env, offsetof(CPUM68KState, macc[i]), p); p +=5 ;
Signature · 1 line
2.55.0
PATCH v2 15/17 target/rx: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format dissassembly index, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- target/rx/disas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/rx/disas.c +1 -1
@@ -167,7 +167,7 @@ static void rx_index_addr(DisasContext *ctx, char out[8], int ld, int mi)g_assert_not_reached (); } -sprintf (out,"%u" , dsp << (mi <3 ? mi :4 - mi)); +snprintf (out,8 ,"%u" , dsp << (mi <3 ? mi :4 - mi)); } static void prt_ldmi(DisasContext *ctx, const char *insn,
Signature · 1 line
2.55.0
Re: [PATCH v2 15/17] target/rx: Replace deprecated sprintf() with snprintf()
Quoted 26 lines · Philippe Mathieu-Daudé
Replace
sprintf()by safersnprintf()to format dissassembly index, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/rx/disas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/rx/disas.c +1
-1@@ -167,7 +167,7 @@ static void rx_index_addr(DisasContext *ctx, char out[8], int ld, int mi)g_assert_not_reached (); } -sprintf (out,"%u" , dsp << (mi <3 ? mi :4 - mi)); +snprintf (out,8 ,"%u" , dsp << (mi <3 ? mi :4 - mi)); } static void prt_ldmi(DisasContext *ctx, const char *insn,Signature · 1 line
2.55.0
Signature · 1 line
Yosinori Sato
PATCH v2 16/17 libdecnumber: Replace deprecated sprintf() with snprintf()
In reply to Philippe Mathieu-DaudéReplace sprintf() by safer snprintf() to format hexadecimal debug, silencing -Wdeprecated-declarations produced by Apple clang 17.0.0.
--- libdecnumber/dpd/decimal128.c | 4 ++-- libdecnumber/dpd/decimal32.c | 4 ++-- libdecnumber/dpd/decimal64.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
libdecnumber/dpd/decimal128.c +2 -2
@@ -543,7 +543,7 @@ void decimal128Show(const decimal128 *d128) {if (DECLITEND ) {for (i=0 ; i<DECIMAL128_Bytes; i++, j+=2 ) { -sprintf (&buf[j],"%02x" , d128->bytes[15 -i]); +snprintf (&buf[j],sizeof (buf) - j,"%02x" , d128->bytes[15 -i]); } printf(" D128> %s [S:%d Cb:%02x Ec:%02x] LittleEndian\n", buf, d128->bytes[15]>>7, (d128->bytes[15]>>2)&0x1f,
@@ -552,7 +552,7 @@ void decimal128Show(const decimal128 *d128) { }else {for (i=0 ; i<DECIMAL128_Bytes; i++, j+=2 ) { -sprintf (&buf[j],"%02x" , d128->bytes[i]); +snprintf (&buf[j],sizeof (buf) - j,"%02x" , d128->bytes[i]); } printf(" D128> %s [S:%d Cb:%02x Ec:%02x] BigEndian\n", buf, decimal128Sign(d128), decimal128Comb(d128),
libdecnumber/dpd/decimal32.c +2 -2
@@ -470,7 +470,7 @@ void decimal32Show(const decimal32 *d32) {if (DECLITEND ) {for (i=0 ; i<DECIMAL32_Bytes; i++, j+=2 ) { -sprintf (&buf[j],"%02x" , d32->bytes[3 -i]); +snprintf (&buf[j],sizeof (buf) - j,"%02x" , d32->bytes[3 -i]); } printf(" D32> %s [S:%d Cb:%02x Ec:%02x] LittleEndian\n", buf, d32->bytes[3]>>7, (d32->bytes[3]>>2)&0x1f,
@@ -478,7 +478,7 @@ void decimal32Show(const decimal32 *d32) { }else {for (i=0 ; i<DECIMAL32_Bytes; i++, j+=2 ) { -sprintf (&buf[j],"%02x" , d32->bytes[i]); +snprintf (&buf[j],sizeof (buf) - j,"%02x" , d32->bytes[i]); }printf (" D32> %s [S:%d Cb:%02x Ec:%02x] BigEndian\n" , buf,decimal32Sign (d32),decimal32Comb (d32),decimal32ExpCon (d32));
libdecnumber/dpd/decimal64.c +2 -2
@@ -530,7 +530,7 @@ void decimal64Show(const decimal64 *d64) {if (DECLITEND ) {for (i=0 ; i<DECIMAL64_Bytes; i++, j+=2 ) { -sprintf (&buf[j],"%02x" , d64->bytes[7 -i]); +snprintf (&buf[j],sizeof (buf) - j,"%02x" , d64->bytes[7 -i]); } printf(" D64> %s [S:%d Cb:%02x Ec:%02x] LittleEndian\n", buf, d64->bytes[7]>>7, (d64->bytes[7]>>2)&0x1f,
@@ -538,7 +538,7 @@ void decimal64Show(const decimal64 *d64) { }else {/* big-endian */ for (i=0 ; i<DECIMAL64_Bytes; i++, j+=2 ) { -sprintf (&buf[j],"%02x" , d64->bytes[i]); +snprintf (&buf[j],sizeof (buf) - j,"%02x" , d64->bytes[i]); }printf (" D64> %s [S:%d Cb:%02x Ec:%02x] BigEndian\n" , buf,decimal64Sign (d64),decimal64Comb (d64),decimal64ExpCon (d64));
Signature · 1 line
2.55.0
PATCH v2 17/17 qga/vss-win32: Replace deprecated sprintf() by StrCatBuffA()
In reply to Philippe Mathieu-DaudéFormatting is not necessary, replace the deprecated sprintf() by StrCpyNA() and StrCatBuffA() calls.
--- qga/vss-win32/install.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
qga/vss-win32/install.cpp +12 -5
@@ -562,7 +562,8 @@ STDAPI DllRegisterServer(void) /* Add this module to registry */ - sprintf(key, "CLSID\\%s", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); if (!CreateRegistryKey(key, NULL, g_szClsid)) { goto out; }
@@ -572,7 +573,9 @@ STDAPI DllRegisterServer(void) goto out; } - sprintf(key, "CLSID\\%s\\InprocServer32", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); + StrCatBuffA(key, "\\InprocServer32", sizeof(key)); if (!CreateRegistryKey(key, NULL, dllPath)) { goto out; }
@@ -581,7 +584,9 @@ STDAPI DllRegisterServer(void) goto out; } - sprintf(key, "CLSID\\%s\\ProgID", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); + StrCatBuffA(key, "\\ProgID", sizeof(key)); if (!CreateRegistryKey(key, NULL, g_szProgid)) { goto out; }
@@ -590,7 +595,8 @@ STDAPI DllRegisterServer(void) goto out; } - sprintf(key, "%s\\CLSID", g_szProgid); + StrCpyNA(key, g_szProgid, sizeof(key)); + StrCatBuffA(key, "\\CLSID", sizeof(key)); if (!CreateRegistryKey(key, NULL, g_szClsid)) { goto out; }
@@ -651,7 +657,8 @@ STDAPI DllUnregisterServer(void) errmsg(hr, "CoCreateInstance(VSSCoordinator) failed"); } - sprintf(key, "CLSID\\%s", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); SHDeleteKey(HKEY_CLASSES_ROOT, key); SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);
Signature · 1 line
2.55.0
Re: [PATCH v2 17/17] qga/vss-win32: Replace deprecated sprintf() by StrCatBuffA()
Quoted 13 lines · Philippe Mathieu-Daudé
Formatting is not necessary, replace the deprecated
sprintf()byStrCpyNA()andStrCatBuffA()calls.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/vss-win32/install.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)qga/vss-win32/install.cpp +0
-0
qga/vss-win32/install.cpp STDAPI DllRegisterServer(void) · line 567
Quoted 7 lines
qga/vss-win32/install.cpp +2
-1@@ -562,7 +562,8 @@ STDAPI DllRegisterServer(void) /* Add this module to registry */ - sprintf(key, "CLSID\\%s", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key));
MSFT does not recommend to use StrCatBuffA due to security warning. What about using StringCchCatA instead of snprintf, even in this case?
Quoted 49 lines
qga/vss-win32/install.cpp +0
-0if (!CreateRegistryKey(key, NULL, g_szClsid)) { goto out;}qga/vss-win32/install.cpp +10
-5@@ -572,7 +573,9 @@ STDAPI DllRegisterServer(void) goto out; } - sprintf(key, "CLSID\\%s\\InprocServer32", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); + StrCatBuffA(key, "\\InprocServer32", sizeof(key)); if (!CreateRegistryKey(key, NULL, dllPath)) { goto out; }@@ -581,7 +584,9 @@ STDAPI DllRegisterServer(void) goto out; } - sprintf(key, "CLSID\\%s\\ProgID", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); + StrCatBuffA(key, "\\ProgID", sizeof(key)); if (!CreateRegistryKey(key, NULL, g_szProgid)) { goto out; }@@ -590,7 +595,8 @@ STDAPI DllRegisterServer(void) goto out; } - sprintf(key, "%s\\CLSID", g_szProgid); + StrCpyNA(key, g_szProgid, sizeof(key)); + StrCatBuffA(key, "\\CLSID", sizeof(key)); if (!CreateRegistryKey(key, NULL, g_szClsid)) { goto out; }@@ -651,7 +657,8 @@ STDAPI DllUnregisterServer(void) errmsg(hr, "CoCreateInstance(VSSCoordinator) failed"); } - sprintf(key, "CLSID\\%s", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key)); SHDeleteKey(HKEY_CLASSES_ROOT, key); SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid); --2.55.0
Re: [PATCH v2 17/17] qga/vss-win32: Replace deprecated sprintf() by StrCatBuffA()
Quoted 19 lines · Kostiantyn Kostiuk
Quoted 16 lines · Philippe Mathieu-Daudé
Formatting is not necessary, replace the deprecated
sprintf()byStrCpyNA()andStrCatBuffA()calls.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/vss-win32/install.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)qga/vss-win32/install.cpp +0
-0@@ -562,7 +562,8 @@ STDAPI DllRegisterServer(void) /* Add this module to registry */
Quoted 7 lines
qga/vss-win32/install.cpp STDAPI DllUnregisterServer(void) · line 664
Quoted 4 lines
qga/vss-win32/install.cpp +2
-1- sprintf(key, "CLSID\\%s", g_szClsid); + StrCpyNA(key, "CLSID\\", sizeof(key)); + StrCatBuffA(key, g_szClsid, sizeof(key));MSFT does not recommend to use StrCatBuffA due to security warning. What about using StringCchCatA instead of snprintf, even in this case?
Good point. I went back with StringCchPrintfA() for less code churn.