From 352b7113d016b2b64418586d57d052e4318f2d3d Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 3 Nov 2026 21:35:10 +0000 Subject: [PATCH] fix(qwen3-tts-cpp): read the PCM buffer without go vet's unsafe.Pointer warning go vet reported "possible misuse of unsafe.Pointer" for the uintptr that the C library returns, and the //nolint:govet comment does not silence vet itself. The line dates from the move to qwentts.cpp, not from the batching work. It is not a bug: the buffer is malloc'd by the C side, so the Go GC neither moves nor frees it, and it is copied out before CppPCMFree runs. Read the address through a pointer to the variable instead of converting the uintptr, which is the form vet accepts and gives the same address. Assisted-by: Claude:claude-sonnet-5-5 go-vet --- backend/go/qwen3-tts-cpp/goqwen3ttscpp.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/go/qwen3-tts-cpp/goqwen3ttscpp.go b/backend/go/qwen3-tts-cpp/goqwen3ttscpp.go index c65a1f1d8e..c470e79f53 100644 --- a/backend/go/qwen3-tts-cpp/goqwen3ttscpp.go +++ b/backend/go/qwen3-tts-cpp/goqwen3ttscpp.go @@ -218,7 +218,11 @@ func (q *Qwen3TtsCpp) TTS(req *pb.TTSRequest) error { if n <= 0 { return fmt.Errorf("qwen3-tts: synthesis produced no samples") } - src := unsafe.Slice((*float32)(unsafe.Pointer(ptr)), int(n)) //nolint:govet // C-allocated PCM, copied out before free + // ptr addresses malloc'd PCM, not Go memory, so the GC neither moves nor + // frees it. Reinterpret the uintptr's bits as a pointer instead of + // converting it: this is the form go vet accepts, and it is the same + // address. + src := unsafe.Slice(*(**float32)(unsafe.Pointer(&ptr)), int(n)) out := make([]float32, int(n)) copy(out, src) return writeWAV24k(req.Dst, out)