aboutsummaryrefslogtreecommitdiffstats
path: root/awk.h
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2017-01-27 13:25:02 -0500
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2017-01-27 13:25:02 -0500
commita7addf98875555f48f30e7a9260f39a36a7b3e75 (patch)
tree585ab531aaf54a667a4b5618bf9b476d0eaf4793 /awk.h
parentf1507d4056a6f4e2a9cd5091a495175cbfb840ae (diff)
downloadegawk-a7addf98875555f48f30e7a9260f39a36a7b3e75.tar.gz
egawk-a7addf98875555f48f30e7a9260f39a36a7b3e75.tar.bz2
egawk-a7addf98875555f48f30e7a9260f39a36a7b3e75.zip
Introduce some helpful macros for terminating strings, and fix overrun in dcgettext.
Diffstat (limited to 'awk.h')
-rw-r--r--awk.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/awk.h b/awk.h
index 9a5c94a8..4ad9c717 100644
--- a/awk.h
+++ b/awk.h
@@ -1958,3 +1958,19 @@ erealloc_real(void *ptr, size_t count, const char *where, const char *var, const
return ret;
}
+
+/*
+ * str_terminate_f, str_terminate, str_restore: function and macros to
+ * reduce chances of typos when terminating and restoring strings.
+ * This also helps to enforce that the NODE must be in scope when we restore.
+ */
+
+static inline void
+str_terminate_f(NODE *n, char *savep)
+{
+ *savep = n->stptr[n->stlen];
+ n->stptr[n->stlen] = '\0';
+}
+
+#define str_terminate(n, save) str_terminate_f((n), &save)
+#define str_restore(n, save) (n)->stptr[(n)->stlen] = save