hw/misc: Avoid sprintf() in the imx devices
PATCH 1/1 hw/misc: Avoid sprintf() in the imx devices
Various imx devices in hw/misc have a pattern in the debug logging where a function which prints register names has a fallback case for an unknown offset that uses sprintf(). Use snprintf() instead to avoid warnings on macos. (The buffer could never overflow because it is 20 bytes and we will write at most 10 digits plus 4 nondigits plus NUL.)
Commit created with:
sed -i -e 's/sprintf(unknown/snprintf(unknown, sizeof(unknown)/' hw/misc/imx*
---
Philippe: here's an easy sprintf->snprintf conversion for your pile :-)
hw/misc/imx25_ccm.c | 2 +- hw/misc/imx31_ccm.c | 2 +- hw/misc/imx6_ccm.c | 4 ++-- hw/misc/imx6_src.c | 2 +- hw/misc/imx6ul_ccm.c | 4 ++-- hw/misc/imx7_src.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
hw/misc/imx25_ccm.c +1 -1
@@ -91,7 +91,7 @@ static const char *imx25_ccm_reg_name(uint32_t reg)case IMX25_CCM_LPIMR1_REG :return "lpimr1" ;default : -sprintf (unknown,"[%u ?]" , reg); +snprintf (unknown,sizeof (unknown),"[%u ?]" , reg);return unknown; } }
hw/misc/imx31_ccm.c +1 -1
@@ -89,7 +89,7 @@ static const char *imx31_ccm_reg_name(uint32_t reg)case IMX31_CCM_PDR2_REG :return "PDR2" ;default : -sprintf (unknown,"[%u ?]" , reg); +snprintf (unknown,sizeof (unknown),"[%u ?]" , reg);return unknown; } }
hw/misc/imx6_ccm.c +2 -2
@@ -85,7 +85,7 @@ static const char *imx6_ccm_reg_name(uint32_t reg)case CCM_CMEOR :return "CMEOR" ;default : -sprintf (unknown,"%u ?" , reg); +snprintf (unknown,sizeof (unknown),"%u ?" , reg);return unknown; } }
@@ -224,7 +224,7 @@ static const char *imx6_analog_reg_name(uint32_t reg)case USB_ANALOG_DIGPROG :return "USB_ANALOG_DIGPROG" ;default : -sprintf (unknown,"%u ?" , reg); +snprintf (unknown,sizeof (unknown),"%u ?" , reg);return unknown; } }
hw/misc/imx6_src.c +1 -1
@@ -68,7 +68,7 @@ static const char *imx6_src_reg_name(uint32_t reg)case SRC_GPR10 :return "SRC_GPR10" ;default : -sprintf (unknown,"%u ?" , reg); +snprintf (unknown,sizeof (unknown),"%u ?" , reg);return unknown; } }
hw/misc/imx6ul_ccm.c +2 -2
@@ -143,7 +143,7 @@ static const char *imx6ul_ccm_reg_name(uint32_t reg)case CCM_CMEOR :return "CMEOR" ;default : -sprintf (unknown,"%u ?" , reg); +snprintf (unknown,sizeof (unknown),"%u ?" , reg);return unknown; } }
@@ -274,7 +274,7 @@ static const char *imx6ul_analog_reg_name(uint32_t reg)case USB_ANALOG_DIGPROG :return "USB_ANALOG_DIGPROG" ;default : -sprintf (unknown,"%u ?" , reg); +snprintf (unknown,sizeof (unknown),"%u ?" , reg);return unknown; } }
hw/misc/imx7_src.c +1 -1
@@ -75,7 +75,7 @@ static const char *imx7_src_reg_name(uint32_t reg)case SRC_GPR10 :return "SRC_GPR10" ;default : -sprintf (unknown,"%u ?" , reg); +snprintf (unknown,sizeof (unknown),"%u ?" , reg);return unknown; } }
Signature · 1 line
2.34.1
Quoted 8 lines · Peter Maydell
Various imx devices in hw/misc have a pattern in the debug logging where a function which prints register names has a fallback case for an unknown offset that uses
sprintf(). Usesnprintf()instead to avoid warnings on macos. (The buffer could never overflow because it is 20 bytes and we will write at most 10 digits plus 4 nondigits plus NUL.)
Quoted 7 lines
Commit created with:
sed -i -e 's/sprintf(unknown/snprintf(unknown, sizeof(unknown)/' hw/misc/imx*
Signed-off-by Peter Maydell <[email protected]>---
Philippe: here's an easysprintf->snprintfconversion for your pile :-)
Never mind, I hadn't noticed you'd sent a second patchset on the sprintf issue, and you've already covered this one.
-- PMM