Message ID | 20240412073346.458116-25-richard.henderson@linaro.org |
---|---|
State | New |
Headers | show |
Series | misc: Replace sprintf | expand |
On 12/4/24 09:33, Richard Henderson wrote: > From: Philippe Mathieu-Daudé <philmd@linaro.org> > > sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1, > resulting in painful developper experience. Use snprintf() instead. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > Message-Id: <20240411104340.6617-7-philmd@linaro.org> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > hw/net/rocker/rocker.c | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) > switch (offset) { > case ROCKER_DMA_DESC_ADDR_OFFSET: > - sprintf(buf, "Ring[%s] ADDR", ring_name); > + snprintf(buf, sizeofbuf), "Ring[%s] ADDR", ring_name); Ideally we should convert the DEBUG_FOO guards to trace events, to avoid to maintain dead code.
On 4/12/24 03:58, Philippe Mathieu-Daudé wrote: > On 12/4/24 09:33, Richard Henderson wrote: >> From: Philippe Mathieu-Daudé <philmd@linaro.org> >> >> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1, >> resulting in painful developper experience. Use snprintf() instead. >> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >> Message-Id: <20240411104340.6617-7-philmd@linaro.org> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> >> --- >> hw/net/rocker/rocker.c | 24 ++++++++++++------------ >> 1 file changed, 12 insertions(+), 12 deletions(-) > > >> switch (offset) { >> case ROCKER_DMA_DESC_ADDR_OFFSET: >> - sprintf(buf, "Ring[%s] ADDR", ring_name); >> + snprintf(buf, sizeofbuf), "Ring[%s] ADDR", ring_name); > > Ideally we should convert the DEBUG_FOO guards to trace events, > to avoid to maintain dead code. Grr, I knew there was another of these that needed fixing up. r~
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c index 7ea8eb6ba5..03ac7a7ae9 100644 --- a/hw/net/rocker/rocker.c +++ b/hw/net/rocker/rocker.c @@ -915,40 +915,40 @@ static const char *rocker_reg_name(void *opaque, hwaddr addr) switch (index) { case 0: - sprintf(ring_name, "cmd"); + snprintf(ring_name, sizeof(ring_name), "cmd"); break; case 1: - sprintf(ring_name, "event"); + snprintf(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, sizeofbuf), "Ring[%s] ADDR", ring_name); return buf; case ROCKER_DMA_DESC_ADDR_OFFSET+4: - sprintf(buf, "Ring[%s] ADDR+4", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] ADDR+4", ring_name); return buf; case ROCKER_DMA_DESC_SIZE_OFFSET: - sprintf(buf, "Ring[%s] SIZE", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] SIZE", ring_name); return buf; case ROCKER_DMA_DESC_HEAD_OFFSET: - sprintf(buf, "Ring[%s] HEAD", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] HEAD", ring_name); return buf; case ROCKER_DMA_DESC_TAIL_OFFSET: - sprintf(buf, "Ring[%s] TAIL", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] TAIL", ring_name); return buf; case ROCKER_DMA_DESC_CTRL_OFFSET: - sprintf(buf, "Ring[%s] CTRL", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] CTRL", ring_name); return buf; case ROCKER_DMA_DESC_CREDITS_OFFSET: - sprintf(buf, "Ring[%s] CREDITS", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] CREDITS", ring_name); return buf; default: - sprintf(buf, "Ring[%s] ???", ring_name); + snprintf(buf, sizeofbuf), "Ring[%s] ???", ring_name); return buf; } } else {