Просмотр исходного кода

marshal: fix marshalling of ints with a wrong type (#1058)

When trying to marshal a value with the wrong type into a
int, smallint or tinyint, marshalInt, marshalSmallint and marshalTinyint
fail with a panic because IsNil is called on a non-pointer value.
Vincent Rischmann 7 лет назад
Родитель
Сommit
1303a32993
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      marshal.go

+ 3 - 3
marshal.go

@@ -330,7 +330,7 @@ func marshalSmallInt(info TypeInfo, value interface{}) ([]byte, error) {
 			return nil, marshalErrorf("marshal smallint: value %d out of range", v)
 		}
 		return encShort(int16(v)), nil
-	default:
+	case reflect.Ptr:
 		if rv.IsNil() {
 			return nil, nil
 		}
@@ -414,7 +414,7 @@ func marshalTinyInt(info TypeInfo, value interface{}) ([]byte, error) {
 			return nil, marshalErrorf("marshal tinyint: value %d out of range", v)
 		}
 		return []byte{byte(v)}, nil
-	default:
+	case reflect.Ptr:
 		if rv.IsNil() {
 			return nil, nil
 		}
@@ -486,7 +486,7 @@ func marshalInt(info TypeInfo, value interface{}) ([]byte, error) {
 			return nil, marshalErrorf("marshal int: value %d out of range", v)
 		}
 		return encInt(int32(v)), nil
-	default:
+	case reflect.Ptr:
 		if rv.IsNil() {
 			return nil, nil
 		}