There was an error while loading. Please reload this page.
1 parent 6ff03b5 commit 372781bCopy full SHA for 372781b
safeptr.go
@@ -19,9 +19,11 @@ limitations under the License.
19
20
package klog
21
22
-// SafePtr accepts a pointer of any type (T) as an argument and returns th
+// SafePtr accepts a pointer of any type (T) as an argument and returns the
23
// same pointer if it's not nil, otherwise it returns nil.
24
-// This function is useful for safely handling pointers and preventing nil pointer dereferencing.
+// This function is useful for safely handling pointers and preventing nil pointer dereferencing when the type
25
+//
26
+// a) implements interfaces called by the logger like `fmt.Stringer` and b) those implementations do not check for nil themselves.
27
func SafePtr[T any](p *T) any {
28
if p == nil {
29
return nil
0 commit comments