1// Code generated by go run decgen.go -output dec_helpers.go; DO NOT EDIT.23// Copyright 2014 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.67package gob89import (10 "math"11 "reflect"12)1314var decArrayHelper = map[reflect.Kind]decHelper{15 reflect.Bool: decBoolArray,16 reflect.Complex64: decComplex64Array,17 reflect.Complex128: decComplex128Array,18 reflect.Float32: decFloat32Array,19 reflect.Float64: decFloat64Array,20 reflect.Int: decIntArray,21 reflect.Int16: decInt16Array,22 reflect.Int32: decInt32Array,23 reflect.Int64: decInt64Array,24 reflect.Int8: decInt8Array,25 reflect.String: decStringArray,26 reflect.Uint: decUintArray,27 reflect.Uint16: decUint16Array,28 reflect.Uint32: decUint32Array,29 reflect.Uint64: decUint64Array,30 reflect.Uintptr: decUintptrArray,31}3233var decSliceHelper = map[reflect.Kind]decHelper{34 reflect.Bool: decBoolSlice,35 reflect.Complex64: decComplex64Slice,36 reflect.Complex128: decComplex128Slice,37 reflect.Float32: decFloat32Slice,38 reflect.Float64: decFloat64Slice,39 reflect.Int: decIntSlice,40 reflect.Int16: decInt16Slice,41 reflect.Int32: decInt32Slice,42 reflect.Int64: decInt64Slice,43 reflect.Int8: decInt8Slice,44 reflect.String: decStringSlice,45 reflect.Uint: decUintSlice,46 reflect.Uint16: decUint16Slice,47 reflect.Uint32: decUint32Slice,48 reflect.Uint64: decUint64Slice,49 reflect.Uintptr: decUintptrSlice,50}5152func decBoolArray(state *decoderState, v reflect.Value, length int, ovfl error) bool {53 // Can only slice if it is addressable.54 if !v.CanAddr() {55 return false56 }57 return decBoolSlice(state, v.Slice(0, v.Len()), length, ovfl)58}5960func decBoolSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {61 slice, ok := reflect.TypeAssert[[]bool](v)62 if !ok {63 // It is kind bool but not type bool. TODO: We can handle this unsafely.64 return false65 }66 for i := 0; i < length; i++ {67 if state.b.Len() == 0 {68 errorf("decoding bool array or slice: length exceeds input size (%d elements)", length)69 }70 if i >= len(slice) {71 // This is a slice that we only partially allocated.72 growSlice(v, &slice, length)73 }74 slice[i] = state.decodeUint() != 075 }76 return true77}7879func decComplex64Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {80 // Can only slice if it is addressable.81 if !v.CanAddr() {82 return false83 }84 return decComplex64Slice(state, v.Slice(0, v.Len()), length, ovfl)85}8687func decComplex64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {88 slice, ok := reflect.TypeAssert[[]complex64](v)89 if !ok {90 // It is kind complex64 but not type complex64. TODO: We can handle this unsafely.91 return false92 }93 for i := 0; i < length; i++ {94 if state.b.Len() == 0 {95 errorf("decoding complex64 array or slice: length exceeds input size (%d elements)", length)96 }97 if i >= len(slice) {98 // This is a slice that we only partially allocated.99 growSlice(v, &slice, length)100 }101 real := float32FromBits(state.decodeUint(), ovfl)102 imag := float32FromBits(state.decodeUint(), ovfl)103 slice[i] = complex(float32(real), float32(imag))104 }105 return true106}107108func decComplex128Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {109 // Can only slice if it is addressable.110 if !v.CanAddr() {111 return false112 }113 return decComplex128Slice(state, v.Slice(0, v.Len()), length, ovfl)114}115116func decComplex128Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {117 slice, ok := reflect.TypeAssert[[]complex128](v)118 if !ok {119 // It is kind complex128 but not type complex128. TODO: We can handle this unsafely.120 return false121 }122 for i := 0; i < length; i++ {123 if state.b.Len() == 0 {124 errorf("decoding complex128 array or slice: length exceeds input size (%d elements)", length)125 }126 if i >= len(slice) {127 // This is a slice that we only partially allocated.128 growSlice(v, &slice, length)129 }130 real := float64FromBits(state.decodeUint())131 imag := float64FromBits(state.decodeUint())132 slice[i] = complex(real, imag)133 }134 return true135}136137func decFloat32Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {138 // Can only slice if it is addressable.139 if !v.CanAddr() {140 return false141 }142 return decFloat32Slice(state, v.Slice(0, v.Len()), length, ovfl)143}144145func decFloat32Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {146 slice, ok := reflect.TypeAssert[[]float32](v)147 if !ok {148 // It is kind float32 but not type float32. TODO: We can handle this unsafely.149 return false150 }151 for i := 0; i < length; i++ {152 if state.b.Len() == 0 {153 errorf("decoding float32 array or slice: length exceeds input size (%d elements)", length)154 }155 if i >= len(slice) {156 // This is a slice that we only partially allocated.157 growSlice(v, &slice, length)158 }159 slice[i] = float32(float32FromBits(state.decodeUint(), ovfl))160 }161 return true162}163164func decFloat64Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {165 // Can only slice if it is addressable.166 if !v.CanAddr() {167 return false168 }169 return decFloat64Slice(state, v.Slice(0, v.Len()), length, ovfl)170}171172func decFloat64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {173 slice, ok := reflect.TypeAssert[[]float64](v)174 if !ok {175 // It is kind float64 but not type float64. TODO: We can handle this unsafely.176 return false177 }178 for i := 0; i < length; i++ {179 if state.b.Len() == 0 {180 errorf("decoding float64 array or slice: length exceeds input size (%d elements)", length)181 }182 if i >= len(slice) {183 // This is a slice that we only partially allocated.184 growSlice(v, &slice, length)185 }186 slice[i] = float64FromBits(state.decodeUint())187 }188 return true189}190191func decIntArray(state *decoderState, v reflect.Value, length int, ovfl error) bool {192 // Can only slice if it is addressable.193 if !v.CanAddr() {194 return false195 }196 return decIntSlice(state, v.Slice(0, v.Len()), length, ovfl)197}198199func decIntSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {200 slice, ok := reflect.TypeAssert[[]int](v)201 if !ok {202 // It is kind int but not type int. TODO: We can handle this unsafely.203 return false204 }205 for i := 0; i < length; i++ {206 if state.b.Len() == 0 {207 errorf("decoding int array or slice: length exceeds input size (%d elements)", length)208 }209 if i >= len(slice) {210 // This is a slice that we only partially allocated.211 growSlice(v, &slice, length)212 }213 x := state.decodeInt()214 // MinInt and MaxInt215 if x < ^int64(^uint(0)>>1) || int64(^uint(0)>>1) < x {216 error_(ovfl)217 }218 slice[i] = int(x)219 }220 return true221}222223func decInt16Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {224 // Can only slice if it is addressable.225 if !v.CanAddr() {226 return false227 }228 return decInt16Slice(state, v.Slice(0, v.Len()), length, ovfl)229}230231func decInt16Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {232 slice, ok := reflect.TypeAssert[[]int16](v)233 if !ok {234 // It is kind int16 but not type int16. TODO: We can handle this unsafely.235 return false236 }237 for i := 0; i < length; i++ {238 if state.b.Len() == 0 {239 errorf("decoding int16 array or slice: length exceeds input size (%d elements)", length)240 }241 if i >= len(slice) {242 // This is a slice that we only partially allocated.243 growSlice(v, &slice, length)244 }245 x := state.decodeInt()246 if x < math.MinInt16 || math.MaxInt16 < x {247 error_(ovfl)248 }249 slice[i] = int16(x)250 }251 return true252}253254func decInt32Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {255 // Can only slice if it is addressable.256 if !v.CanAddr() {257 return false258 }259 return decInt32Slice(state, v.Slice(0, v.Len()), length, ovfl)260}261262func decInt32Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {263 slice, ok := reflect.TypeAssert[[]int32](v)264 if !ok {265 // It is kind int32 but not type int32. TODO: We can handle this unsafely.266 return false267 }268 for i := 0; i < length; i++ {269 if state.b.Len() == 0 {270 errorf("decoding int32 array or slice: length exceeds input size (%d elements)", length)271 }272 if i >= len(slice) {273 // This is a slice that we only partially allocated.274 growSlice(v, &slice, length)275 }276 x := state.decodeInt()277 if x < math.MinInt32 || math.MaxInt32 < x {278 error_(ovfl)279 }280 slice[i] = int32(x)281 }282 return true283}284285func decInt64Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {286 // Can only slice if it is addressable.287 if !v.CanAddr() {288 return false289 }290 return decInt64Slice(state, v.Slice(0, v.Len()), length, ovfl)291}292293func decInt64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {294 slice, ok := reflect.TypeAssert[[]int64](v)295 if !ok {296 // It is kind int64 but not type int64. TODO: We can handle this unsafely.297 return false298 }299 for i := 0; i < length; i++ {300 if state.b.Len() == 0 {301 errorf("decoding int64 array or slice: length exceeds input size (%d elements)", length)302 }303 if i >= len(slice) {304 // This is a slice that we only partially allocated.305 growSlice(v, &slice, length)306 }307 slice[i] = state.decodeInt()308 }309 return true310}311312func decInt8Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {313 // Can only slice if it is addressable.314 if !v.CanAddr() {315 return false316 }317 return decInt8Slice(state, v.Slice(0, v.Len()), length, ovfl)318}319320func decInt8Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {321 slice, ok := reflect.TypeAssert[[]int8](v)322 if !ok {323 // It is kind int8 but not type int8. TODO: We can handle this unsafely.324 return false325 }326 for i := 0; i < length; i++ {327 if state.b.Len() == 0 {328 errorf("decoding int8 array or slice: length exceeds input size (%d elements)", length)329 }330 if i >= len(slice) {331 // This is a slice that we only partially allocated.332 growSlice(v, &slice, length)333 }334 x := state.decodeInt()335 if x < math.MinInt8 || math.MaxInt8 < x {336 error_(ovfl)337 }338 slice[i] = int8(x)339 }340 return true341}342343func decStringArray(state *decoderState, v reflect.Value, length int, ovfl error) bool {344 // Can only slice if it is addressable.345 if !v.CanAddr() {346 return false347 }348 return decStringSlice(state, v.Slice(0, v.Len()), length, ovfl)349}350351func decStringSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {352 slice, ok := reflect.TypeAssert[[]string](v)353 if !ok {354 // It is kind string but not type string. TODO: We can handle this unsafely.355 return false356 }357 for i := 0; i < length; i++ {358 if state.b.Len() == 0 {359 errorf("decoding string array or slice: length exceeds input size (%d elements)", length)360 }361 if i >= len(slice) {362 // This is a slice that we only partially allocated.363 growSlice(v, &slice, length)364 }365 u := state.decodeUint()366 n := int(u)367 if n < 0 || uint64(n) != u || n > state.b.Len() {368 errorf("length of string exceeds input size (%d bytes)", u)369 }370 if n > state.b.Len() {371 errorf("string data too long for buffer: %d", n)372 }373 // Read the data.374 data := state.b.Bytes()375 if len(data) < n {376 errorf("invalid string length %d: exceeds input size %d", n, len(data))377 }378 slice[i] = string(data[:n])379 state.b.Drop(n)380 }381 return true382}383384func decUintArray(state *decoderState, v reflect.Value, length int, ovfl error) bool {385 // Can only slice if it is addressable.386 if !v.CanAddr() {387 return false388 }389 return decUintSlice(state, v.Slice(0, v.Len()), length, ovfl)390}391392func decUintSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {393 slice, ok := reflect.TypeAssert[[]uint](v)394 if !ok {395 // It is kind uint but not type uint. TODO: We can handle this unsafely.396 return false397 }398 for i := 0; i < length; i++ {399 if state.b.Len() == 0 {400 errorf("decoding uint array or slice: length exceeds input size (%d elements)", length)401 }402 if i >= len(slice) {403 // This is a slice that we only partially allocated.404 growSlice(v, &slice, length)405 }406 x := state.decodeUint()407 /*TODO if math.MaxUint32 < x {408 error_(ovfl)409 }*/410 slice[i] = uint(x)411 }412 return true413}414415func decUint16Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {416 // Can only slice if it is addressable.417 if !v.CanAddr() {418 return false419 }420 return decUint16Slice(state, v.Slice(0, v.Len()), length, ovfl)421}422423func decUint16Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {424 slice, ok := reflect.TypeAssert[[]uint16](v)425 if !ok {426 // It is kind uint16 but not type uint16. TODO: We can handle this unsafely.427 return false428 }429 for i := 0; i < length; i++ {430 if state.b.Len() == 0 {431 errorf("decoding uint16 array or slice: length exceeds input size (%d elements)", length)432 }433 if i >= len(slice) {434 // This is a slice that we only partially allocated.435 growSlice(v, &slice, length)436 }437 x := state.decodeUint()438 if math.MaxUint16 < x {439 error_(ovfl)440 }441 slice[i] = uint16(x)442 }443 return true444}445446func decUint32Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {447 // Can only slice if it is addressable.448 if !v.CanAddr() {449 return false450 }451 return decUint32Slice(state, v.Slice(0, v.Len()), length, ovfl)452}453454func decUint32Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {455 slice, ok := reflect.TypeAssert[[]uint32](v)456 if !ok {457 // It is kind uint32 but not type uint32. TODO: We can handle this unsafely.458 return false459 }460 for i := 0; i < length; i++ {461 if state.b.Len() == 0 {462 errorf("decoding uint32 array or slice: length exceeds input size (%d elements)", length)463 }464 if i >= len(slice) {465 // This is a slice that we only partially allocated.466 growSlice(v, &slice, length)467 }468 x := state.decodeUint()469 if math.MaxUint32 < x {470 error_(ovfl)471 }472 slice[i] = uint32(x)473 }474 return true475}476477func decUint64Array(state *decoderState, v reflect.Value, length int, ovfl error) bool {478 // Can only slice if it is addressable.479 if !v.CanAddr() {480 return false481 }482 return decUint64Slice(state, v.Slice(0, v.Len()), length, ovfl)483}484485func decUint64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {486 slice, ok := reflect.TypeAssert[[]uint64](v)487 if !ok {488 // It is kind uint64 but not type uint64. TODO: We can handle this unsafely.489 return false490 }491 for i := 0; i < length; i++ {492 if state.b.Len() == 0 {493 errorf("decoding uint64 array or slice: length exceeds input size (%d elements)", length)494 }495 if i >= len(slice) {496 // This is a slice that we only partially allocated.497 growSlice(v, &slice, length)498 }499 slice[i] = state.decodeUint()500 }501 return true502}503504func decUintptrArray(state *decoderState, v reflect.Value, length int, ovfl error) bool {505 // Can only slice if it is addressable.506 if !v.CanAddr() {507 return false508 }509 return decUintptrSlice(state, v.Slice(0, v.Len()), length, ovfl)510}511512func decUintptrSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {513 slice, ok := reflect.TypeAssert[[]uintptr](v)514 if !ok {515 // It is kind uintptr but not type uintptr. TODO: We can handle this unsafely.516 return false517 }518 for i := 0; i < length; i++ {519 if state.b.Len() == 0 {520 errorf("decoding uintptr array or slice: length exceeds input size (%d elements)", length)521 }522 if i >= len(slice) {523 // This is a slice that we only partially allocated.524 growSlice(v, &slice, length)525 }526 x := state.decodeUint()527 if uint64(^uintptr(0)) < x {528 error_(ovfl)529 }530 slice[i] = uintptr(x)531 }532 return true533}534535// growSlice is called for a slice that we only partially allocated,536// to grow it up to length.537func growSlice[E any](v reflect.Value, ps *[]E, length int) {538 var zero E539 s := *ps540 s = append(s, zero)541 cp := cap(s)542 if cp > length {543 cp = length544 }545 s = s[:cp]546 v.Set(reflect.ValueOf(s))547 *ps = s548}
Findings
✓ No findings reported for this file.