瀏覽代碼

x/model: copy text in UnmarshalText

Blake Mizerany 1 年之前
父節點
當前提交
07f27312fa
共有 1 個文件被更改,包括 3 次插入8 次删除
  1. 3 8
      x/model/name.go

+ 3 - 8
x/model/name.go

@@ -11,7 +11,6 @@ import (
 	"slices"
 	"strings"
 	"sync"
-	"unsafe"
 
 	"github.com/ollama/ollama/x/types/structs"
 )
@@ -333,14 +332,10 @@ func (r *Name) UnmarshalText(text []byte) error {
 		// the immutability of the Name.
 		return errors.New("model.Name: UnmarshalText on valid Name")
 	}
-	// unsafeString is safe here because the contract of UnmarshalText
-	// that text belongs to us for the duration of the call.
-	*r = ParseName(unsafeString(text))
-	return nil
-}
 
-func unsafeString(b []byte) string {
-	return *(*string)(unsafe.Pointer(&b))
+	// The contract of UnmarshalText  is that we copy to keep the text.
+	*r = ParseName(string(text))
+	return nil
 }
 
 // Complete reports whether the Name is fully qualified. That is it has a