diff options
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -606,10 +606,16 @@ cmp_nodes(NODE *t1, NODE *t2, bool use_strcmp) if (IGNORECASE) { const unsigned char *cp1 = (const unsigned char *) t1->stptr; const unsigned char *cp2 = (const unsigned char *) t2->stptr; + char save1 = t1->stptr[t1->stlen]; + char save2 = t2->stptr[t2->stlen]; + if (gawk_mb_cur_max > 1) { + t1->stptr[t1->stlen] = t2->stptr[t2->stlen] = '\0'; ret = strncasecmpmbs((const unsigned char *) cp1, (const unsigned char *) cp2, l); + t1->stptr[t1->stlen] = save1; + t2->stptr[t2->stlen] = save2; } else { /* Could use tolower() here; see discussion above. */ for (ret = 0; l-- > 0 && ret == 0; cp1++, cp2++) @@ -853,6 +859,8 @@ fmt_ok(NODE *n) static const char flags[] = " +-#"; #endif + // We rely on the caller to zero-terminate n->stptr. + if (*p++ != '%') return 0; while (*p && strchr(flags, *p) != NULL) /* flags */ @@ -880,15 +888,21 @@ fmt_index(NODE *n) int ix = 0; static int fmt_num = 4; static int fmt_hiwater = 0; + char save; if (fmt_list == NULL) emalloc(fmt_list, NODE **, fmt_num*sizeof(*fmt_list), "fmt_index"); n = force_string(n); + + save = n->stptr[n->stlen]; + n->stptr[n->stlen] = '\0'; + while (ix < fmt_hiwater) { if (cmp_nodes(fmt_list[ix], n, true) == 0) return ix; ix++; } + /* not found */ if (do_lint && ! fmt_ok(n)) lintwarn(_("bad `%sFMT' specification `%s'"), @@ -896,6 +910,8 @@ fmt_index(NODE *n) : n == OFMT_node->var_value ? "O" : "", n->stptr); + n->stptr[n->stlen] = save; + if (fmt_hiwater >= fmt_num) { fmt_num *= 2; erealloc(fmt_list, NODE **, fmt_num * sizeof(*fmt_list), "fmt_index"); |