1
0
mirror of https://github.com/golang/go synced 2024-09-30 18:28:32 -06:00

fmt: catch overflow in width and prec calculations

Fixes #10674.

Change-Id: If3fae3244d87aeaa70815f499105c264394aa7ad
Reviewed-on: https://go-review.googlesource.com/9657
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Rob Pike 2015-05-04 11:28:51 -07:00
parent b86e71f5aa
commit 660a6825ea
2 changed files with 4 additions and 0 deletions

View File

@ -537,6 +537,7 @@ var fmtTests = []struct {
{"%s", nil, "%!s(<nil>)"},
{"%T", nil, "<nil>"},
{"%-1", 100, "%!(NOVERB)%!(EXTRA int=100)"},
{"%017091901790959340919092959340919017929593813360", 0, "%!(NOVERB)%!(EXTRA int=0)"},
// The "<nil>" show up because maps are printed by
// first obtaining a list of keys and then looking up

View File

@ -292,6 +292,9 @@ func parsenum(s string, start, end int) (num int, isnum bool, newi int) {
}
for newi = start; newi < end && '0' <= s[newi] && s[newi] <= '9'; newi++ {
num = num*10 + int(s[newi]-'0')
if num < 0 {
return 0, false, end // Overflow; crazy long number most likely.
}
isnum = true
}
return