From 8587ba272ede9b6607ec06822e743db71f3ba563 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 28 May 2025 11:26:17 +0200 Subject: [PATCH] cmd/cgo: compare malloc return value to NULL instead of literal 0 Follow the pattern used in the other _cgoPREFIX_Cfunc* functions. This also avoids a -Wzero-as-null-pointer-constant warning when compiling with g++. Change-Id: I95ac8842df048105f4c738f3603136d9cfa2dfdc Reviewed-on: https://go-review.googlesource.com/c/go/+/664916 Auto-Submit: Keith Randall Auto-Submit: Tobias Klauser Reviewed-by: Keith Randall Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- src/cmd/cgo/out.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 10870b7c85..dfa54e41d3 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -1812,7 +1812,7 @@ void _cgoPREFIX_Cfunc__Cmalloc(void *v) { void *ret; _cgo_tsan_acquire(); ret = malloc(a->p0); - if (ret == 0 && a->p0 == 0) { + if (ret == NULL && a->p0 == 0) { ret = malloc(1); } a->r1 = ret; -- 2.51.0