aboutsummaryrefslogtreecommitdiffstats
path: root/formats/objfile/common.go
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-27 14:07:22 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-27 14:07:22 -0800
commit31f920a06aa5d7e7cf363645dac02f6e798fffb1 (patch)
treeddd60f794c193e1a407e78b5ca94d0a83466fd78 /formats/objfile/common.go
parente6855829c4df2861e779adcccbb422e7c0830afd (diff)
downloadgo-git-31f920a06aa5d7e7cf363645dac02f6e798fffb1.tar.gz
Improved objfile error handling and test coverage
Diffstat (limited to 'formats/objfile/common.go')
-rw-r--r--formats/objfile/common.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/formats/objfile/common.go b/formats/objfile/common.go
index 7389086..2f0585f 100644
--- a/formats/objfile/common.go
+++ b/formats/objfile/common.go
@@ -13,6 +13,8 @@ var (
ErrClosed = errors.New("objfile: already closed")
// ErrHeader is returned when the objfile has an invalid header.
ErrHeader = errors.New("objfile: invalid header")
+ // ErrNegativeSize is returned when a negative object size is declared.
+ ErrNegativeSize = errors.New("objfile: negative object size")
)
type header struct {
@@ -38,7 +40,11 @@ func (h *header) Read(r io.Reader) error {
h.size, err = strconv.ParseInt(string(size), 10, 64)
if err != nil {
- return err
+ return ErrHeader
+ }
+
+ if h.size < 0 {
+ return ErrNegativeSize
}
return nil