mirror of
https://github.com/mudler/LocalAI.git
synced 2026-11-06 04:23:15 -05:00
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
This commit is contained in:
1 file changed
+5
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user