diff options
author | Michael Forney <mforney@mforney.org> | 2020-01-30 22:23:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-31 08:23:34 +0200 |
commit | 69325710b145823367d4c21c8b55c0657305bd1c (patch) | |
tree | 40e0e3b7c4d634a340d069129328518a7f8eedbc | |
parent | 4d9b12969eaa9770fecda1f90b465939675ce5d0 (diff) | |
download | one-true-awk-69325710b145823367d4c21c8b55c0657305bd1c.tar.gz |
Use MB_LEN_MAX instead of MB_CUR_MAX to avoid VLA (#70)
MB_CUR_MAX is the maximum number of bytes in a multibyte character
for the current locale, and might not be a constant expression.
MB_LEN_MAX is the maximum number of bytes in a multibyte character
for any locale, and always expands to a constant-expression.
-rw-r--r-- | lib.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -29,6 +29,7 @@ THIS SOFTWARE. #include <errno.h> #include <stdlib.h> #include <stdarg.h> +#include <limits.h> #include "awk.h" #include "ytab.h" @@ -343,14 +344,14 @@ void fldbld(void) /* create fields from current record */ *fr = 0; } else if ((sep = *inputFS) == 0) { /* new: FS="" => 1 char/field */ for (i = 0; *r != '\0'; r += n) { - char buf[MB_CUR_MAX + 1]; + char buf[MB_LEN_MAX + 1]; i++; if (i > nfields) growfldtab(i); if (freeable(fldtab[i])) xfree(fldtab[i]->sval); - n = mblen(r, MB_CUR_MAX); + n = mblen(r, MB_LEN_MAX); if (n < 0) n = 1; memcpy(buf, r, n); |