1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:20:22 -07:00

gob: turn two panics into errors because they can be triggered

by bogus data, or are in any case recoverable.

Fixes #1598.

R=rsc
CC=golang-dev
https://golang.org/cl/4240101
This commit is contained in:
Rob Pike 2011-03-09 17:30:27 -08:00
parent a16af59fd1
commit f8f3145a08
2 changed files with 6 additions and 5 deletions

View File

@ -19,7 +19,7 @@ import (
var (
errBadUint = os.ErrorString("gob: encoded unsigned integer out of range")
errBadType = os.ErrorString("gob: unknown type id or corrupted data")
errRange = os.ErrorString("gob: internal error: field numbers out of bounds")
errRange = os.ErrorString("gob: bad data: field numbers out of bounds")
)
// decoderState is the execution state of an instance of the decoder. A new state
@ -885,7 +885,7 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId) decOp {
wire := dec.wireType[wireId]
switch {
case wire == nil:
panic("internal error: can't find ignore op for type " + wireId.string())
errorf("gob: bad data: undefined type %s", wireId.string())
case wire.ArrayT != nil:
elemId := wire.ArrayT.Elem
elemOp := dec.decIgnoreOpFor(elemId)
@ -927,7 +927,7 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId) decOp {
}
}
if op == nil {
errorf("ignore can't handle type %s", wireId.string())
errorf("gob: bad data: ignore can't handle type %s", wireId.string())
}
return op
}

View File

@ -579,7 +579,8 @@ func methodIndex(rt reflect.Type, method string) int {
return i
}
}
panic("can't find method " + method)
errorf("gob: internal error: can't find method %s", method)
return 0
}
// gobEncodeOpFor returns the op for a type that is known to implement
@ -628,7 +629,7 @@ func (enc *Encoder) compileEnc(ut *userTypeInfo) *encEngine {
wireFieldNum++
}
if srt.NumField() > 0 && len(engine.instr) == 0 {
errorf("type %s has no exported fields", rt)
errorf("gob: type %s has no exported fields", rt)
}
engine.instr = append(engine.instr, encInstr{encStructTerminator, 0, 0, 0})
} else {