aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-02-05 21:34:03 +0200
committerArnold D. Robbins <arnold@skeeve.com>2017-02-05 21:34:03 +0200
commit125c0cc16af6d57fa6b7fa19420e3e957f4e85ac (patch)
tree527ddbd7c3afc47a7b2f4f25f58ebb3db89f48c8
parentca87b9c44b803aa1eb97d8f61ba7939ee618195d (diff)
parent21cc2dc13d48aaa70b88d7a190ea8b4b830986f4 (diff)
downloadegawk-125c0cc16af6d57fa6b7fa19420e3e957f4e85ac.tar.gz
egawk-125c0cc16af6d57fa6b7fa19420e3e957f4e85ac.tar.bz2
egawk-125c0cc16af6d57fa6b7fa19420e3e957f4e85ac.zip
Merge branch 'master' into feature/fix-comments
-rw-r--r--ChangeLog5
-rw-r--r--awkgram.c7
-rw-r--r--awkgram.y7
3 files changed, 13 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 43681e6e..c492147c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-03 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * awkgram.y (set_profile_text): Improve code clarity by using emalloc
+ to allocate the string instead of abusing estrdup.
+
2017-02-02 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (set_profile_next): Allocate an extra byte at the
diff --git a/awkgram.c b/awkgram.c
index 6e2c7b0d..b8ead514 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -8737,9 +8737,10 @@ static NODE *
set_profile_text(NODE *n, const char *str, size_t len)
{
if (do_pretty_print) {
- // extra byte in case we need to add minus sign in negate_num
- // note that estrdup adds another byte for the \0 at the end
- n->stptr = estrdup(str, len + 1);
+ // two extra bytes: one for NUL termination, and another in
+ // case we need to add a leading minus sign in add_sign_to_num
+ emalloc(n->stptr, char *, len + 2, "set_profile_text");
+ memcpy(n->stptr, str, len);
n->stptr[len] = '\0';
n->stlen = len;
// Set STRCUR and n->stfmt for use when profiling
diff --git a/awkgram.y b/awkgram.y
index bda85186..cc263183 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -6309,9 +6309,10 @@ static NODE *
set_profile_text(NODE *n, const char *str, size_t len)
{
if (do_pretty_print) {
- // extra byte in case we need to add minus sign in negate_num
- // note that estrdup adds another byte for the \0 at the end
- n->stptr = estrdup(str, len + 1);
+ // two extra bytes: one for NUL termination, and another in
+ // case we need to add a leading minus sign in add_sign_to_num
+ emalloc(n->stptr, char *, len + 2, "set_profile_text");
+ memcpy(n->stptr, str, len);
n->stptr[len] = '\0';
n->stlen = len;
// Set STRCUR and n->stfmt for use when profiling