Merge pull request #12 from iamleot/cc_func-avoid-undefined-behaviour

Avoid undefined behaviour when using ctype(3) functions in relex() (possible fix for #11)
This commit is contained in:
onetrueawk 2019-03-03 15:08:25 -05:00 committed by GitHub
commit 115fac0587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

3
b.c
View File

@ -27,6 +27,7 @@ THIS SOFTWARE.
#define DEBUG #define DEBUG
#include <ctype.h> #include <ctype.h>
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -831,7 +832,7 @@ int relex(void) /* lexical analyzer for reparse */
* not without first adapting the entire * not without first adapting the entire
* program to track each string's length. * program to track each string's length.
*/ */
for (i = 1; i < NCHARS; i++) { for (i = 1; i <= UCHAR_MAX; i++) {
if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2")) if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2"))
FATAL("out of space for reg expr %.10s...", lastre); FATAL("out of space for reg expr %.10s...", lastre);
if (cc->cc_func(i)) { if (cc->cc_func(i)) {