summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorJacek Sieka <arnetheduck@gmail.com>2015-03-29 22:25:11 +0800
committerJacek Sieka <arnetheduck@gmail.com>2015-04-01 22:32:15 +0800
commitaafbe5c866e21a4078dee16f52219a1ab9fec926 (patch)
tree9888e5905fe6624f20a347dba1f08f0bc7adf1ef /compiler
parent91f42a294396d86e8ee7386f94de29c44be60cf2 (diff)
downloadNim-aafbe5c866e21a4078dee16f52219a1ab9fec926.tar.gz
ropes: make lib & compiler frmt more similar, fix out-of-bounds accesses in lib ropes
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ropes.nim16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/ropes.nim b/compiler/ropes.nim
index af9917d9a..f1d4c1b6f 100644
--- a/compiler/ropes.nim
+++ b/compiler/ropes.nim
@@ -264,12 +264,26 @@ proc `%`*(frmt: TFormatStr, args: openArray[PRope]): PRope =
         while true:
           j = j * 10 + ord(frmt[i]) - ord('0')
           inc(i)
-          if (i > length - 1) or frmt[i] notin {'0'..'9'}: break
+          if (i >= length) or frmt[i] notin {'0'..'9'}: break
         num = j
         if j > high(args) + 1:
           errorHandler(rInvalidFormatStr, $(j))
         else:
           add(result, args[j-1])
+      of '{':
+        inc(i)
+        var j = 0
+        while i < length and frmt[i] in {'0'..'9'}:
+          j = j * 10 + ord(frmt[i]) - ord('0')
+          inc(i)
+        num = j
+        if i < length and frmt[i] == '}': inc(i)
+        else: errorHandler(rInvalidFormatStr, $(frmt[i]))
+
+        if j > high(args) + 1:
+          errorHandler(rInvalidFormatStr, $(j))
+        else:
+          add(result, args[j-1])
       of 'n':
         add(result, softRnl)
         inc(i)