Fix hanging when requested zero-length string.

Add test for NewLen from 0 to 100.
This commit is contained in:
Dmitry Chestnykh 2015-01-21 18:36:13 +01:00
parent e80eb311f3
commit 7668ee6861
2 changed files with 12 additions and 0 deletions

View file

@ -53,6 +53,9 @@ func NewLen(length int) string {
// NewLenChars returns a new random string of the provided length, consisting
// of the provided byte slice of allowed characters (maximum 256).
func NewLenChars(length int, chars []byte) string {
if length == 0 {
return ""
}
b := make([]byte, length)
r := make([]byte, length+(length/4)) // storage for random bytes.
clen := len(chars)