MCPcopy
hub / github.com/tinylib/msgp / TestReadIntBytesOverflows

Function TestReadIntBytesOverflows

msgp/read_bytes_test.go:370–479  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

368}
369
370func TestReadIntBytesOverflows(t *testing.T) {
371 var buf bytes.Buffer
372 wr := NewWriter(&buf)
373
374 i8, i16, i32, i64, u8, u16, u32, u64 := 1, 2, 3, 4, 5, 6, 7, 8
375
376 overflowErr := func(err error, failBits int) bool {
377 bits := 0
378 switch err := err.(type) {
379 case IntOverflow:
380 bits = err.FailedBitsize
381 case UintOverflow:
382 bits = err.FailedBitsize
383 }
384 if bits == failBits {
385 return true
386 }
387 log.Println("bits mismatch", bits, failBits)
388 return false
389 }
390
391 belowZeroErr := func(err error, failBits int) bool {
392 switch err.(type) {
393 case UintBelowZero:
394 return true
395 }
396 return false
397 }
398
399 vs := []struct {
400 v any
401 rdBits int
402 failBits int
403 errCheck func(err error, failBits int) bool
404 }{
405 {uint64(math.MaxInt64), i32, 32, overflowErr},
406 {uint64(math.MaxInt64), i16, 16, overflowErr},
407 {uint64(math.MaxInt64), i8, 8, overflowErr},
408
409 {uint64(math.MaxUint64), i64, 64, overflowErr},
410 {uint64(math.MaxUint64), i32, 64, overflowErr},
411 {uint64(math.MaxUint64), i16, 64, overflowErr},
412 {uint64(math.MaxUint64), i8, 64, overflowErr},
413
414 {uint64(math.MaxUint32), i32, 32, overflowErr},
415 {uint64(math.MaxUint32), i16, 16, overflowErr},
416 {uint64(math.MaxUint32), i8, 8, overflowErr},
417
418 {int64(math.MinInt64), u64, 64, belowZeroErr},
419 {int64(math.MinInt64), u32, 64, belowZeroErr},
420 {int64(math.MinInt64), u16, 64, belowZeroErr},
421 {int64(math.MinInt64), u8, 64, belowZeroErr},
422 {int64(math.MinInt32), u64, 64, belowZeroErr},
423 {int64(math.MinInt32), u32, 32, belowZeroErr},
424 {int64(math.MinInt32), u16, 16, belowZeroErr},
425 {int64(math.MinInt32), u8, 8, belowZeroErr},
426 {int64(math.MinInt16), u64, 64, belowZeroErr},
427 {int64(math.MinInt16), u32, 32, belowZeroErr},

Callers

nothing calls this directly

Calls 13

WriteInt64Method · 0.95
WriteUint64Method · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
ReadInt64BytesFunction · 0.85
ReadInt32BytesFunction · 0.85
ReadInt16BytesFunction · 0.85
ReadInt8BytesFunction · 0.85
ReadUint64BytesFunction · 0.85
ReadUint32BytesFunction · 0.85
ReadUint16BytesFunction · 0.85
ReadUint8BytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…