--- var.c 2002/01/02 17:12:18 1.58
+++ var.c 2002/01/09 11:27:07 1.59
@@ -1272,7 +1272,7 @@
/* Compile the pattern. */
- rc = regcomp(&preg, tmp.begin, REG_EXTENDED|((case_insensitive)?REG_ICASE:0));
+ rc = regcomp(&preg, tmp.begin, REG_NEWLINE | REG_EXTENDED|((case_insensitive)?REG_ICASE:0));
tokenbuf_free(&tmp);
if (rc != 0) {
tokenbuf_free(&mydata);
@@ -1287,9 +1287,8 @@
regexec_flag = 0;
else
regexec_flag = REG_NOTBOL;
- if (regexec
- (&preg, p, sizeof(pmatch) / sizeof(regmatch_t), pmatch,
- regexec_flag) == REG_NOMATCH) {
+ if (regexec(&preg, p, sizeof(pmatch) / sizeof(regmatch_t), pmatch, regexec_flag) == REG_NOMATCH ||
+ p + pmatch[0].rm_so == mydata.end) {
tokenbuf_append(&tmp, p, mydata.end - p);
break;
} else {
@@ -1309,11 +1308,28 @@
tokenbuf_free(&myreplace);
return VAR_ERR_OUT_OF_MEMORY;
} else {
- p += (pmatch[0].rm_eo > 0) ? pmatch[0].rm_eo : 1;
+ p += pmatch[0].rm_eo;
+ if (pmatch[0].rm_eo - pmatch[0].rm_so == 0)
+ {
+ if (!tokenbuf_append(&tmp, p, 1))
+ {
+ regfree(&preg);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(&mydata);
+ tokenbuf_free(&myreplace);
+ return VAR_ERR_OUT_OF_MEMORY;
+ }
+ ++p;
+ }
tokenbuf_free(&myreplace);
}
if (!global) {
- tokenbuf_append(&tmp, p, mydata.end - p);
+ if (!tokenbuf_append(&tmp, p, mydata.end - p)) {
+ regfree(&preg);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(&mydata);
+ return VAR_ERR_OUT_OF_MEMORY;
+ }
break;
}
}
|