]> Cypherpunks repositories - gostls13.git/commitdiff
image/png: remove too early declaration of "n"
authorAyan George <ayan@ayan.net>
Fri, 8 May 2020 04:13:44 +0000 (00:13 -0400)
committerRob Pike <r@golang.org>
Fri, 8 May 2020 22:01:08 +0000 (22:01 +0000)
Before this commit, the code declares and assigns "n" with the result of
io.ReadFull() -- but the value is not used.  The variable is then reused
later in the function.

This commit removes the first declaration of "n" and declares it closer
to where it is used.

Change-Id: I7ffe19a10f2a563c306bb6fe6562493435b9dc5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/232917
Reviewed-by: Rob Pike <r@golang.org>
src/image/png/reader.go

index 5521b39bb0cd2e43e09857c23e1c089dc7316347..910520bd4b343037a2941494626cd00420f6533d 100644 (file)
@@ -862,8 +862,7 @@ func (d *decoder) parseIEND(length uint32) error {
 
 func (d *decoder) parseChunk() error {
        // Read the length and chunk type.
-       n, err := io.ReadFull(d.r, d.tmp[:8])
-       if err != nil {
+       if _, err := io.ReadFull(d.r, d.tmp[:8]); err != nil {
                return err
        }
        length := binary.BigEndian.Uint32(d.tmp[:4])
@@ -920,7 +919,7 @@ func (d *decoder) parseChunk() error {
        // Ignore this chunk (of a known length).
        var ignored [4096]byte
        for length > 0 {
-               n, err = io.ReadFull(d.r, ignored[:min(len(ignored), int(length))])
+               n, err := io.ReadFull(d.r, ignored[:min(len(ignored), int(length))])
                if err != nil {
                        return err
                }