aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2017-06-25 23:20:54 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2017-06-25 23:20:54 -0400
commitc07e72504d045f8e5070668e61fa5d8a3290ab66 (patch)
tree27881767587e12327c16d39ef3cce5915e90b1c6
parent44e29458a6355ad64e8d89676a441b224ce76cbc (diff)
downloadegawk-c07e72504d045f8e5070668e61fa5d8a3290ab66.tar.gz
egawk-c07e72504d045f8e5070668e61fa5d8a3290ab66.tar.bz2
egawk-c07e72504d045f8e5070668e61fa5d8a3290ab66.zip
Remove xmalloc from gawkmisc.c, and improve dfa xalloc by using calloc instead of malloc+memset.
-rw-r--r--ChangeLog4
-rw-r--r--gawkmisc.c16
-rw-r--r--helpers/ChangeLog5
-rw-r--r--helpers/testdfa.c11
-rw-r--r--support/ChangeLog7
-rw-r--r--support/dfa.c7
-rw-r--r--support/xalloc.h21
7 files changed, 43 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d9a5b98..9bfff326 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-06-25 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * gawkmisc.c (xmalloc): Remove function now in support/xalloc.h.
+
2017-06-22 Arnold D. Robbins <arnold@skeeve.com>
Make pretty-printing include parentheses that were explicitly
diff --git a/gawkmisc.c b/gawkmisc.c
index f1658921..bef4f365 100644
--- a/gawkmisc.c
+++ b/gawkmisc.c
@@ -41,19 +41,3 @@
#include "posix/gawkmisc.c"
#endif /* not VMS */
#endif /* not __DJGPP__, not __MINGW32__ */
-
-/* xmalloc --- provide this so that other GNU library routines work */
-
-typedef void *pointer;
-
-extern pointer xmalloc(size_t bytes); /* get rid of gcc warning */
-
-pointer
-xmalloc(size_t bytes)
-{
- pointer p;
- if (bytes == 0)
- bytes = 1; /* avoid dfa.c mishegos */
- emalloc(p, pointer, bytes, "xmalloc");
- return p;
-}
diff --git a/helpers/ChangeLog b/helpers/ChangeLog
index ce3fd9ca..bd7e5486 100644
--- a/helpers/ChangeLog
+++ b/helpers/ChangeLog
@@ -1,3 +1,8 @@
+2017-06-25 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * testdfa.c (xcalloc): Replace xmalloc+memset with calloc.
+ (xzalloc): Replace xmalloc+memset with xcalloc.
+
2017-04-26 Arnold D. Robbins <arnold@skeeve.com>
* test-build.sh: Allow override of compiler lists. Print
diff --git a/helpers/testdfa.c b/helpers/testdfa.c
index 72b97907..f61d4e26 100644
--- a/helpers/testdfa.c
+++ b/helpers/testdfa.c
@@ -880,8 +880,13 @@ xnmalloc (size_t n, size_t s)
void *
xcalloc(size_t nmemb, size_t size)
{
- void *p = xmalloc (nmemb * size);
- memset(p, '\0', nmemb * size);
+ void *p = calloc (nmemb, size);
+
+ if (p == NULL) {
+ fprintf(stderr, "xcalloc: calloc failed: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
return p;
}
@@ -1031,7 +1036,7 @@ xcharalloc (size_t n)
void *
xzalloc (size_t s)
{
- return memset (xmalloc (s), 0, s);
+ return xcalloc (1, s);
}
# endif
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