[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 9/9] target/i386: Replace sprintf() by snprintf()
From: |
Peter Maydell |
Subject: |
Re: [PATCH 9/9] target/i386: Replace sprintf() by snprintf() |
Date: |
Thu, 11 Apr 2024 12:59:20 +0100 |
On Thu, 11 Apr 2024 at 11:44, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> 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>
> ---
> target/i386/kvm/kvm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index e68cbe9293..a46d1426bf 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -5335,7 +5335,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run
> *run)
> case KVM_EXIT_NOTIFY:
> ctx_invalid = !!(run->notify.flags & KVM_NOTIFY_CONTEXT_INVALID);
> state = KVM_STATE(current_accel());
> - sprintf(str, "Encounter a notify exit with %svalid context in"
> + snprintf(str, sizeof(str),
> + "Encounter a notify exit with %svalid context in"
> " guest. There can be possible misbehaves in guest."
> " Please have a look.", ctx_invalid ? "in" : "");
> if (ctx_invalid ||
> --
This is a case where I think we would be better off with
g_strdup_printf():
* the buffer declaration is a long way away from its use
* the string is long and it's not trivial to confirm that
it will fit in the buffer
* it's quite plausible somebody will come along later to
clean up the wording of the error message and not notice
they need to enlarge the buffer
* it's only for printing a warning, so it's not going to
be in a hot codepath
thanks
-- PMM
- Re: [PATCH 5/9] hw/misc/imx: Replace sprintf() by snprintf(), (continued)