Browse Source

codec: represent correctly, that a ptr is nil if it "points" to a nil value.

Previously, during isEmptyValue, we incorrectly represented this. Now fixed.

Fixes #237
Ugorji Nwoke 7 years ago
parent
commit
0332d21115
1 changed files with 2 additions and 1 deletions
  1. 2 1
      codec/helper_unsafe.go

+ 2 - 1
codec/helper_unsafe.go

@@ -157,7 +157,8 @@ func isEmptyValue(v reflect.Value, tinfos *TypeInfos, deref, checkStruct bool) b
 		}
 		return isnil
 	case reflect.Ptr:
-		isnil := urv.ptr == nil
+		// isnil := urv.ptr == nil (not sufficient, as a pointer value encodes the type)
+		isnil := urv.ptr == nil || *(*unsafe.Pointer)(urv.ptr) == nil
 		if deref {
 			if isnil {
 				return true