FAQ
A small code review. Reviewers: r,

Message:
Hello r@golang.org (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go.text


Description:
go.text/encoding: fix off-by-one error in some decoders returning
ErrShortDst even when there is sufficient dst space.

In theory, a transform.Transformer is allowed to return fewer dst bytes
than maximal, but in practice, we shouldn't be wasteful.

Please review this at https://codereview.appspot.com/13512045/

Affected files +10, -5:
    M encoding/encoding_test.go
    M encoding/japanese/eucjp.go
    M encoding/japanese/shiftjis.go
    M encoding/simplifiedchinese/gbk.go


Index: encoding/encoding_test.go
===================================================================
--- a/encoding/encoding_test.go
+++ b/encoding/encoding_test.go
@@ -189,18 +189,23 @@
       wPrefix, sPrefix = tc.encPrefix, ""
      }

- dst := make([]byte, 1024)
+ dst := make([]byte, len(wPrefix)+len(want))
      nDst, nSrc, err := newTransformer().Transform(dst, []byte(sPrefix+src),
true)
      if err != nil {
       t.Errorf("%v: %s: %v", tc.e, direction, err)
       continue
      }
+ if nDst != len(wPrefix)+len(want) {
+ t.Errorf("%v: %s: nDst got %d, want %d",
+ tc.e, direction, nDst, len(wPrefix)+len(want))
+ continue
+ }
      if nSrc != len(sPrefix)+len(src) {
       t.Errorf("%v: %s: nSrc got %d, want %d",
        tc.e, direction, nSrc, len(sPrefix)+len(src))
       continue
      }
- if got := string(dst[:nDst]); got != wPrefix+want {
+ if got := string(dst); got != wPrefix+want {
       t.Errorf("%v: %s:\ngot %q\nwant %q",
        tc.e, direction, got, wPrefix+want)
       continue
Index: encoding/japanese/eucjp.go
===================================================================
--- a/encoding/japanese/eucjp.go
+++ b/encoding/japanese/eucjp.go
@@ -99,7 +99,7 @@
      break loop
     }

- if nDst+utf8.RuneLen(r) >= len(dst) {
+ if nDst+utf8.RuneLen(r) > len(dst) {
      err = transform.ErrShortDst
      break loop
     }
Index: encoding/japanese/shiftjis.go
===================================================================
--- a/encoding/japanese/shiftjis.go
+++ b/encoding/japanese/shiftjis.go
@@ -90,7 +90,7 @@
      break loop
     }

- if nDst+utf8.RuneLen(r) >= len(dst) {
+ if nDst+utf8.RuneLen(r) > len(dst) {
      err = transform.ErrShortDst
      break loop
     }
Index: encoding/simplifiedchinese/gbk.go
===================================================================
--- a/encoding/simplifiedchinese/gbk.go
+++ b/encoding/simplifiedchinese/gbk.go
@@ -76,7 +76,7 @@
      break loop
     }

- if nDst+utf8.RuneLen(r) >= len(dst) {
+ if nDst+utf8.RuneLen(r) > len(dst) {
      err = transform.ErrShortDst
      break loop
     }


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • R at Sep 5, 2013 at 1:55 am
    LGTM

    https://codereview.appspot.com/13512045/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Nigeltao at Sep 5, 2013 at 2:42 am
    *** Submitted as
    https://code.google.com/p/go/source/detail?r=2cad1b12da48&repo=text ***

    go.text/encoding: fix off-by-one error in some decoders returning
    ErrShortDst even when there is sufficient dst space.

    In theory, a transform.Transformer is allowed to return fewer dst bytes
    than maximal, but in practice, we shouldn't be wasteful.

    R=r
    CC=golang-dev
    https://codereview.appspot.com/13512045


    https://codereview.appspot.com/13512045/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 5, '13 at 1:24a
activeSep 5, '13 at 2:42a
posts3
users2
websitegolang.org

2 users in discussion

Nigeltao: 2 posts R: 1 post

People

Translate

site design / logo © 2022 Grokbase