diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-09-07 20:31:11 +0400 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-09-07 20:55:03 +0400 |
commit | bf11db6acaa340e0c8ec39eb27f0f925b45a41e9 (patch) | |
tree | ea858462ebf06cffe7b4be9d13964d285b26f2e2 | |
parent | 8fccbf33dbbc8b94d1907745f0e5bfd8f9f1bb01 (diff) | |
download | nasm-bf11db6acaa340e0c8ec39eb27f0f925b45a41e9.tar.gz |
preproc.c: Make %substr robust
Make %substr robust to handle -1,-1 parameters
and restore old behavior when number of characters
in substring is greater then length of string itself.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r-- | preproc.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -3449,13 +3449,14 @@ issue_error: len = nasm_unquote(t->text, NULL); - /* check the values provided, on error -- empty string */ + /* make start and count being in range */ + if (start < 0) + start = 0; if (count < 0) count = len + count + 1 - start; if (start + count > (int64_t)len) - start = -1; - - if (!len || count < 0 || start < 0) + count = len - start; + if (!len || count < 0 || start >=(int64_t)len) start = -1, count = 0; /* empty string */ macro_start = nasm_malloc(sizeof(*macro_start)); |