[Mesa-dev] [PATCH mesa 4/6] gallivm: ensure string is null-terminated instead of assert()ing

Dylan Baker dylan at pnwbakers.com
Fri Sep 21 15:36:50 UTC 2018


Quoting Eric Engestrom (2018-09-21 06:50:39)
> Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
> ---
>  src/gallium/auxiliary/gallivm/lp_bld_printf.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
> index 575ebdfdf65b7fd43b94..cbfa278728b4ec8f4624 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
> @@ -108,9 +108,7 @@ lp_build_print_value(struct gallivm_state *gallivm,
>        type_fmt[5] = '\0';
>     } else if (type_kind == LLVMIntegerTypeKind) {
>        if (LLVMGetIntTypeWidth(type_ref) == 64) {
> -         unsigned flen = strlen(PRId64);
> -         assert(flen <= 3);
> -         strncpy(type_fmt + 2, PRId64, flen);
> +         snprintf(type_fmt + 2, 3, "%s", PRId64);

I think you need to use util_snprintf here since this code can be used on
windows.

>        } else if (LLVMGetIntTypeWidth(type_ref) == 8) {
>           type_fmt[2] = 'u';
>        } else {
> -- 
> Cheers,
>   Eric
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180921/cd8362f2/attachment.sig>


More information about the mesa-dev mailing list