aboutsummaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-rw-r--r--support/ChangeLog7
-rw-r--r--support/dfa.c7
-rw-r--r--support/xalloc.h21
3 files changed, 26 insertions, 9 deletions
diff --git a/support/ChangeLog b/support/ChangeLog
index ec54675a..bc535ea8 100644
--- a/support/ChangeLog
+++ b/support/ChangeLog
@@ -1,3 +1,10 @@
+2017-06-25 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * dfa.c (dfaalloc): Replace xmalloc+memset with xzalloc.
+ * xalloc.h (xmalloc): New function moved here from gawkmisc.c.
+ (xcalloc): Replace xmalloc+memset with calloc.
+ (xzalloc): Replace xmalloc+memset with xcalloc.
+
2017-06-22 Arnold D. Robbins <arnold@skeeve.com>
* regcomp.c, regex.c, regex.h, regex_internal.c, regex_internal.h,
diff --git a/support/dfa.c b/support/dfa.c
index 18c17a5d..3a675f5d 100644
--- a/support/dfa.c
+++ b/support/dfa.c
@@ -4062,12 +4062,7 @@ dfamustfree (struct dfamust *dm)
struct dfa *
dfaalloc (void)
{
- void *p = xmalloc (sizeof (struct dfa));
- if (p)
- {
- memset (p, 0, sizeof (struct dfa));
- }
- return p;
+ return xzalloc (sizeof (struct dfa));
}
/* Initialize DFA. */
diff --git a/support/xalloc.h b/support/xalloc.h
index 0d169cf9..89dbe2c1 100644
--- a/support/xalloc.h
+++ b/support/xalloc.h
@@ -138,6 +138,17 @@ xnmalloc (size_t n, size_t s)
#include <errno.h>
extern void r_fatal(const char *msg, ...) ATTRIBUTE_NORETURN ;
+void *
+xmalloc(size_t bytes)
+{
+ void *p;
+ if (bytes == 0)
+ bytes = 1; /* avoid dfa.c mishegos */
+ if ((p = malloc(bytes)) == NULL)
+ xalloc_die ();
+ return p;
+}
+
/* Allocate an array of N objects, each with S bytes of memory,
dynamically, with error checking. S must be nonzero.
Clear the contents afterwards. */
@@ -145,8 +156,12 @@ extern void r_fatal(const char *msg, ...) ATTRIBUTE_NORETURN ;
void *
xcalloc(size_t nmemb, size_t size)
{
- void *p = xmalloc (nmemb * size);
- memset(p, '\0', nmemb * size);
+ void *p;
+
+ if (nmemb == 0 || size == 0)
+ nmemb = size = 1; /* avoid dfa.c mishegos */
+ if ((p = calloc(nmemb, size)) == NULL)
+ xalloc_die ();
return p;
}
@@ -314,7 +329,7 @@ xcharalloc (size_t n)
inline void *
xzalloc (size_t s)
{
- return memset (xmalloc (s), 0, s);
+ return xcalloc(1, s);
}
# endif