diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-07-10 15:34:40 -0700 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-07-10 15:34:40 -0700 |
commit | bd29e4330190f4ce26dc1f734229357b6f248a1a (patch) | |
tree | 813ad6fd7826dc56099b0679e6238d8126f7b0ae | |
parent | f6e8ca91a0046536ed5ffef60bb818d674fadf54 (diff) | |
download | egawk-bd29e4330190f4ce26dc1f734229357b6f248a1a.tar.gz egawk-bd29e4330190f4ce26dc1f734229357b6f248a1a.tar.bz2 egawk-bd29e4330190f4ce26dc1f734229357b6f248a1a.zip |
Make source code character checking smarter.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | awkgram.c | 40 | ||||
-rw-r--r-- | awkgram.y | 40 |
3 files changed, 74 insertions, 12 deletions
@@ -1,3 +1,9 @@ +2014-07-10 Arnold D. Robbins <arnold@skeeve.com> + + * awkgram.y (check_for_bad): New routine to do the fatal message, + with smarter checking. + (nextc): Call it as appropriate. + 2014-07-03 Arnold D. Robbins <arnold@skeeve.com> * awkgram.y (nextc): Add bool check_for_bad parameter to check @@ -5130,6 +5130,34 @@ tokexpand() return tok; } +/* check_bad_char --- fatal if c isn't allowed in gawk source code */ + +/* + * The error message was inspired by someone who decided to put + * a physical \0 byte into the source code to see what would + * happen and then filed a bug report about it. Sigh. + */ + +static void +check_bad_char(int c) +{ + /* allow escapes. needed for autoconf. bleah. */ + switch (c) { + case '\a': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + return; + default: + break; + } + + if (iscntrl(c) && ! isspace(c)) + fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c); +} + /* nextc --- get the next input character */ #if MBS_SUPPORT @@ -5186,8 +5214,8 @@ again: 0 : work_ring_idx + 1; cur_char_ring[work_ring_idx] = 0; } - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return (int) (unsigned char) *lexptr++; } else { @@ -5195,8 +5223,8 @@ again: if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -5213,8 +5241,8 @@ nextc(bool check_for_bad) if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -2791,6 +2791,34 @@ tokexpand() return tok; } +/* check_bad_char --- fatal if c isn't allowed in gawk source code */ + +/* + * The error message was inspired by someone who decided to put + * a physical \0 byte into the source code to see what would + * happen and then filed a bug report about it. Sigh. + */ + +static void +check_bad_char(int c) +{ + /* allow escapes. needed for autoconf. bleah. */ + switch (c) { + case '\a': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + return; + default: + break; + } + + if (iscntrl(c) && ! isspace(c)) + fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), c); +} + /* nextc --- get the next input character */ #if MBS_SUPPORT @@ -2847,8 +2875,8 @@ again: 0 : work_ring_idx + 1; cur_char_ring[work_ring_idx] = 0; } - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return (int) (unsigned char) *lexptr++; } else { @@ -2856,8 +2884,8 @@ again: if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); @@ -2874,8 +2902,8 @@ nextc(bool check_for_bad) if (lexeof) return END_FILE; if (lexptr && lexptr < lexend) { - if (check_for_bad && iscntrl(*lexptr) && ! isspace(*lexptr)) - fatal(_("PEBKAC error: invalid character '\\%03o' in source code"), *lexptr); + if (check_for_bad) + check_bad_char(*lexptr); return ((int) (unsigned char) *lexptr++); } } while (get_src_buf()); |