aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--dfa.c23
-rw-r--r--xalloc.h10
3 files changed, 26 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index b431bb8b..f818326a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2012-04-27 Arnold D. Robbins <arnold@skeeve.com>
+ * dfa.c: Sync with GNU grep.
+ * xalloc.h (xmemdup): Added, from grep, for dfa.c. Sigh.
+
+2012-04-27 Arnold D. Robbins <arnold@skeeve.com>
+
Update to autoconf 2.69, automake 1.12.
* INSTALL, aclocal.m4, configh.in, depcomp, install-sh, missing,
diff --git a/dfa.c b/dfa.c
index 21cabc3b..39c07064 100644
--- a/dfa.c
+++ b/dfa.c
@@ -53,7 +53,7 @@
#include "gettext.h"
#define _(str) gettext (str)
-#include "mbsupport.h" /* defines MBS_SUPPORT to 1 or 0, as appropriate */
+#include "mbsupport.h" /* defines MBS_SUPPORT to 1 or 0, as appropriate */
#if MBS_SUPPORT
/* We can handle multibyte strings. */
#include <wchar.h>
@@ -343,7 +343,7 @@ struct mb_char_classes
wchar_t *range_sts; /* Range characters (start of the range). */
wchar_t *range_ends; /* Range characters (end of the range). */
size_t nranges;
- char **equivs; /* Equivalent classes. */
+ char **equivs; /* Equivalence classes. */
size_t nequivs;
char **coll_elems;
size_t ncoll_elems; /* Collating elements. */
@@ -1053,12 +1053,10 @@ parse_bracket_exp (void)
else if (MBS_SUPPORT && (c1 == '=' || c1 == '.'))
{
- char *elem;
- MALLOC (elem, len + 1);
- strncpy (elem, str, len + 1);
+ char *elem = xmemdup (str, len + 1);
if (c1 == '=')
- /* build equivalent class. */
+ /* build equivalence class. */
{
REALLOC_IF_NECESSARY (work_mbc->equivs,
equivs_al, work_mbc->nequivs + 1);
@@ -3021,7 +3019,7 @@ match_mb_charset (struct dfa *d, state_num s, position pos, size_t idx)
strncpy (buffer, (char const *) buf_begin + idx, match_len);
buffer[match_len] = '\0';
- /* match with an equivalent class? */
+ /* match with an equivalence class? */
for (i = 0; i < work_mbc->nequivs; i++)
{
op_len = strlen (work_mbc->equivs[i]);
@@ -3151,6 +3149,8 @@ transit_state_consume_1char (struct dfa *d, state_num s,
if (match_lens == NULL && work_mbls != NULL)
free (work_mbls);
+
+ /* FIXME: this return value is always ignored. */
return rs;
}
@@ -3195,7 +3195,7 @@ transit_state (struct dfa *d, state_num s, unsigned char const **pp)
/* We must update the pointer if state transition succeeded. */
if (rs == TRANSIT_STATE_DONE)
- ++ * pp;
+ ++*pp;
free (match_lens);
return s1;
@@ -3408,7 +3408,7 @@ dfaexec (struct dfa *d, char const *begin, char *end,
if ((char *) p <= end && p[-1] == eol)
{
if (count)
- ++ * count;
+ ++*count;
if (d->mb_cur_max > 1)
prepare_wc_buf ((const char *) p, end);
@@ -3669,7 +3669,7 @@ icatalloc (char *old, char const *new)
if (newsize == 0)
return old;
result = xrealloc (old, oldsize + newsize + 1);
- strcpy (result + oldsize, new);
+ memcpy (result + oldsize, new, newsize + 1);
return result;
}
@@ -4062,8 +4062,7 @@ done:
{
MALLOC (dm, 1);
dm->exact = exact;
- MALLOC (dm->must, strlen (result) + 1);
- strcpy (dm->must, result);
+ dm->must = xmemdup (result, strlen (result) + 1);
dm->next = d->musts;
d->musts = dm;
}
diff --git a/xalloc.h b/xalloc.h
index 5810fc55..eb0ef1a0 100644
--- a/xalloc.h
+++ b/xalloc.h
@@ -169,6 +169,16 @@ xalloc_die (void)
r_fatal(_("xalloc: malloc failed: %s"), strerror(errno));
}
+
+/* Clone an object P of size S, with error checking. There's no need
+ for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
+ need for an arithmetic overflow check. */
+
+void *
+xmemdup (void const *p, size_t s)
+{
+ return memcpy (xmalloc (s), p, s);
+}
#endif
/* Change the size of an allocated block of memory P to an array of N