This commit is contained in:
Andreas Rumpf
2018-03-05 19:45:59 +01:00
parent 1b760dcd66
commit 5c8332d871

View File

@@ -2295,7 +2295,7 @@ proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.
case formatstr[i+1] # again we use the fact that strings
# are zero-terminated here
of '#':
if num >% a.high: invalidFormatString()
if num > a.high: invalidFormatString()
add s, a[num]
inc i, 2
inc num
@@ -2311,7 +2311,7 @@ proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.
j = j * 10 + ord(formatstr[i]) - ord('0')
inc(i)
let idx = if not negative: j-1 else: a.len-j
if idx >% a.high: invalidFormatString()
if idx < 0 or idx > a.high: invalidFormatString()
add s, a[idx]
of '{':
var j = i+2
@@ -2328,7 +2328,7 @@ proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.
inc(j)
if isNumber == 1:
let idx = if not negative: k-1 else: a.len-k
if idx >% a.high: invalidFormatString()
if idx < 0 or idx > a.high: invalidFormatString()
add s, a[idx]
else:
var x = findNormalized(substr(formatstr, i+2, j-1), a)