diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2017-01-27 13:25:02 -0500 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2017-01-27 13:25:02 -0500 |
commit | a7addf98875555f48f30e7a9260f39a36a7b3e75 (patch) | |
tree | 585ab531aaf54a667a4b5618bf9b476d0eaf4793 /awk.h | |
parent | f1507d4056a6f4e2a9cd5091a495175cbfb840ae (diff) | |
download | egawk-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.h | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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 |