]> Cypherpunks repositories - gostls13.git/commitdiff
gob: turn two panics into errors because they can be triggered
authorRob Pike <r@golang.org>
Thu, 10 Mar 2011 01:30:27 +0000 (17:30 -0800)
committerRob Pike <r@golang.org>
Thu, 10 Mar 2011 01:30:27 +0000 (17:30 -0800)
by bogus data, or are in any case recoverable.

Fixes #1598.

R=rsc
CC=golang-dev
https://golang.org/cl/4240101

src/pkg/gob/decode.go
src/pkg/gob/encode.go

index 6d7ddfdfbc1ad2629f7ab48c7905918b473e5a9e..c47fea1a70a5de75ee72fcdb7c4eebac60686c01 100644 (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
 }
index cfee6f6d85f8dd5e559ad5b93b3e50b22a5c00c0..adaf958e783b93b89e07503e6e30d672860b21d7 100644 (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 {