summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Kanios <keith@kanios.net>2011-04-08 01:20:09 -0500
committerKeith Kanios <keith@kanios.net>2011-04-08 01:20:09 -0500
commitf16401f9aabb550a556d3a462f428a3b52f6f9c3 (patch)
tree3b20f1fcae1cfab98cc8d18603749f3b080395ea
parentdd9c9752ead3a39fec6f050bfe3ac8768defc02f (diff)
downloadnasm-f16401f9aabb550a556d3a462f428a3b52f6f9c3.tar.gz
nasmlib.c: fix issues with strrep utility function
-rw-r--r--nasmlib.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 538223f8..c08ef09d 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -295,7 +295,7 @@ char *nasm_strrep(const char *str, const char *sub, char *lin, bool casesense)
char *outline = lin;
char *temp1 = NULL;
char *temp2 = NULL;
- char *l, *lp, *lt, *ls;
+ char *l, *ll, *lp, *lt, *ls;
int count = 0;
int str_len, sub_len, lin_len;
int i, c;
@@ -321,7 +321,7 @@ char *nasm_strrep(const char *str, const char *sub, char *lin, bool casesense)
ls = (char *)str;
}
- lt = l;
+ ll = l;
do {
l = strstr(l, ls);
@@ -336,23 +336,25 @@ char *nasm_strrep(const char *str, const char *sub, char *lin, bool casesense)
i += (count * sub_len);
outline = nasm_zalloc(i);
- l = lt;
+ l = ll;
+ lt = lin;
- for (i = 0; i < count; i ++) {
+ for (i = 0; i < count; i++) {
lp = l;
l = strstr(l, ls);
- c = (lp - l);
+ c = (l - lp);
if (c > 0) {
strncat(outline, lt, c);
+ lt += c;
}
strncat(outline, sub, sub_len);
l += str_len;
lt += str_len;
}
- c = (l - lin);
+ c = (l - ll);
if (c < lin_len) {
- strcat(outline, lt);
+ strncat(outline, lt, (lin_len-c));
}
if (temp2 != NULL) {