[NCF-271]

Fix bug introduced by [NCF-267].
The bug was that octal constants that had
the highest bit set (e.g. '\200')
were not recognized as proper octal
constants. Fix was to keep as integer
until it was needed as an 8-bit byte.
This commit is contained in:
dmh 2013-09-26 10:10:26 -06:00
parent 1aef893cea
commit 850af2d435
8 changed files with 889 additions and 1127 deletions

View File

@ -10,6 +10,11 @@ information, where '[NCF-XXX]' refers to https://www.unidata.ucar.edu/jira/brows
### 4.3.1-rc4 Released TBD ### 4.3.1-rc4 Released TBD
Fix bug introduced by [NCF-267] where octal constants above
'\177' were not recognized as proper octal constants. [NCF-271]
[NCF-271]:https://bugtracking.unidata.ucar.edu/browse/NCF-271
### 4.3.1-rc3 Released 2013-09-24 ### 4.3.1-rc3 Released 2013-09-24
* Modify ncgen to support NUL characters in character array * Modify ncgen to support NUL characters in character array

View File

@ -4,9 +4,14 @@ dimensions:
variables: variables:
char cdata(n) ; char cdata(n) ;
char cdata2(n) ;
// global attributes: // global attributes:
:global = "x\000y" ; :global = "x\000y" ;
:byte_att = '\000','\001','\002','\177','\200','\201','\376','\377';
data: data:
cdata = "abc\000def" ; cdata = "abc\000def" ;
cdata2 = '\000','\001','\002','\177','\200','\201','\376','\377';
} }

View File

@ -3,10 +3,14 @@ dimensions:
n = 8 ; n = 8 ;
variables: variables:
char cdata(n) ; char cdata(n) ;
char cdata2(n) ;
// global attributes: // global attributes:
:global = "x\000y" ; :global = "x\000y" ;
:byte_att = 0b, 1b, 2b, 127b, -128b, -127b, -2b, -1b ;
data: data:
cdata = "abc\000def" ; cdata = "abc\000def" ;
cdata2 = "\000\001\002\177\200\201\376\377" ;
} }

View File

@ -618,7 +618,8 @@ unescapehex(const char* s)
/* /*
* Given a pointer to a string of the form * Given a pointer to a string of the form
* 'ddd', return the corresponding octal byte * 'ddd', return the corresponding
* unsigned octal byte
*/ */
int int
@ -708,6 +709,10 @@ unescape(
case '4': case '5': case '6': case '7': case '4': case '5': case '6': case '7':
/* t now points to octal */ /* t now points to octal */
b = unescapeoct(t); b = unescapeoct(t);
if(b < 0) {
derror("Bad octal constant: %s",yytext);
b = 0;
}
t += 3; t += 3;
*p++ = ((char)b); *p++ = ((char)b);
break; break;

View File

@ -513,19 +513,21 @@ NIL|nil|Nil {
return lexdebug(BYTE_CONST); return lexdebug(BYTE_CONST);
} }
\'\\[0-7][0-7][0-7]\' { \'\\[0-7][0-7][0-7]\' {
byte_val = unescapeoct(&yytext[2]); int oct = unescapeoct(&yytext[2]);
if(byte_val < 0) { if(oct < 0) {
sprintf(errstr,"bad octal character constant: %s",(char*)yytext); sprintf(errstr,"bad octal character constant: %s",(char*)yytext);
yyerror(errstr); yyerror(errstr);
} }
byte_val = (unsigned int)oct;
return lexdebug(BYTE_CONST); return lexdebug(BYTE_CONST);
} }
\'\\[xX][0-9a-fA-F][0-9a-fA-F]\' { \'\\[xX][0-9a-fA-F][0-9a-fA-F]\' {
byte_val = unescapehex(&yytext[3]); int hex = unescapehex(&yytext[3]);
if(byte_val < 0) { if(byte_val < 0) {
sprintf(errstr,"bad hex character constant: %s",(char*)yytext); sprintf(errstr,"bad hex character constant: %s",(char*)yytext);
yyerror(errstr); yyerror(errstr);
} }
byte_val = (unsigned int)hex;
return lexdebug(BYTE_CONST); return lexdebug(BYTE_CONST);
} }
\'\\.\' { \'\\.\' {

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.6.4. */ /* A Bison parser, made by GNU Bison 3.0. */
/* Bison interface for Yacc-like parsers in C /* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -32,7 +32,7 @@
#ifndef YY_NCG_NCGEN_TAB_H_INCLUDED #ifndef YY_NCG_NCGEN_TAB_H_INCLUDED
# define YY_NCG_NCGEN_TAB_H_INCLUDED # define YY_NCG_NCGEN_TAB_H_INCLUDED
/* Enabling traces. */ /* Debug traces. */
#ifndef YYDEBUG #ifndef YYDEBUG
# define YYDEBUG 1 # define YYDEBUG 1
#endif #endif
@ -40,69 +40,68 @@
extern int ncgdebug; extern int ncgdebug;
#endif #endif
/* Tokens. */ /* Token type. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define YYTOKENTYPE # define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers enum yytokentype
know about them. */ {
enum yytokentype { NC_UNLIMITED_K = 258,
NC_UNLIMITED_K = 258, CHAR_K = 259,
CHAR_K = 259, BYTE_K = 260,
BYTE_K = 260, SHORT_K = 261,
SHORT_K = 261, INT_K = 262,
INT_K = 262, FLOAT_K = 263,
FLOAT_K = 263, DOUBLE_K = 264,
DOUBLE_K = 264, UBYTE_K = 265,
UBYTE_K = 265, USHORT_K = 266,
USHORT_K = 266, UINT_K = 267,
UINT_K = 267, INT64_K = 268,
INT64_K = 268, UINT64_K = 269,
UINT64_K = 269, IDENT = 270,
IDENT = 270, TERMSTRING = 271,
TERMSTRING = 271, CHAR_CONST = 272,
CHAR_CONST = 272, BYTE_CONST = 273,
BYTE_CONST = 273, SHORT_CONST = 274,
SHORT_CONST = 274, INT_CONST = 275,
INT_CONST = 275, INT64_CONST = 276,
INT64_CONST = 276, UBYTE_CONST = 277,
UBYTE_CONST = 277, USHORT_CONST = 278,
USHORT_CONST = 278, UINT_CONST = 279,
UINT_CONST = 279, UINT64_CONST = 280,
UINT64_CONST = 280, FLOAT_CONST = 281,
FLOAT_CONST = 281, DOUBLE_CONST = 282,
DOUBLE_CONST = 282, DIMENSIONS = 283,
DIMENSIONS = 283, VARIABLES = 284,
VARIABLES = 284, NETCDF = 285,
NETCDF = 285, DATA = 286,
DATA = 286, TYPES = 287,
TYPES = 287, COMPOUND = 288,
COMPOUND = 288, ENUM = 289,
ENUM = 289, OPAQUE = 290,
OPAQUE = 290, OPAQUESTRING = 291,
OPAQUESTRING = 291, GROUP = 292,
GROUP = 292, PATH = 293,
PATH = 293, FILLMARKER = 294,
FILLMARKER = 294, NIL = 295,
NIL = 295, _FILLVALUE = 296,
_FILLVALUE = 296, _FORMAT = 297,
_FORMAT = 297, _STORAGE = 298,
_STORAGE = 298, _CHUNKSIZES = 299,
_CHUNKSIZES = 299, _DEFLATELEVEL = 300,
_DEFLATELEVEL = 300, _SHUFFLE = 301,
_SHUFFLE = 301, _ENDIANNESS = 302,
_ENDIANNESS = 302, _NOFILL = 303,
_NOFILL = 303, _FLETCHER32 = 304,
_FLETCHER32 = 304, DATASETID = 305
DATASETID = 305 };
};
#endif #endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{ {
/* Line 2077 of yacc.c */ #line 131 "ncgen.y" /* yacc.c:1909 */
#line 131 "ncgen.y"
Symbol* sym; Symbol* sym;
unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/ unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/
@ -111,29 +110,15 @@ int nctype; /* for tracking attribute list type*/
Datalist* datalist; Datalist* datalist;
NCConstant constant; NCConstant constant;
#line 114 "ncgen.tab.h" /* yacc.c:1909 */
/* Line 2077 of yacc.c */ };
#line 117 "ncgen.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
#endif #endif
extern YYSTYPE ncglval; extern YYSTYPE ncglval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int ncgparse (void *YYPARSE_PARAM);
#else
int ncgparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int ncgparse (void); int ncgparse (void);
#else
int ncgparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_NCG_NCGEN_TAB_H_INCLUDED */ #endif /* !YY_NCG_NCGEN_TAB_H_INCLUDED */

View File

@ -1322,7 +1322,7 @@ static int input (void );
/* This used to be an fputs(), but since the string might contain NUL's, /* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite(). * we now use fwrite().
*/ */
#define ECHO do { if (fwrite( ncgtext, ncgleng, 1, ncgout )) {} } while (0) #define ECHO fwrite( ncgtext, ncgleng, 1, ncgout )
#endif #endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@ -1333,7 +1333,7 @@ static int input (void );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \ { \
int c = '*'; \ int c = '*'; \
unsigned n; \ int n; \
for ( n = 0; n < max_size && \ for ( n = 0; n < max_size && \
(c = getc( ncgin )) != EOF && c != '\n'; ++n ) \ (c = getc( ncgin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \ buf[n] = (char) c; \
@ -2000,29 +2000,31 @@ case 42:
YY_RULE_SETUP YY_RULE_SETUP
#line 515 "ncgen.l" #line 515 "ncgen.l"
{ {
byte_val = unescapeoct(&ncgtext[2]); int oct = unescapeoct(&ncgtext[2]);
if(byte_val < 0) { if(oct < 0) {
sprintf(errstr,"bad octal character constant: %s",(char*)ncgtext); sprintf(errstr,"bad octal character constant: %s",(char*)ncgtext);
yyerror(errstr); yyerror(errstr);
} }
byte_val = (unsigned int)oct;
return lexdebug(BYTE_CONST); return lexdebug(BYTE_CONST);
} }
YY_BREAK YY_BREAK
case 43: case 43:
YY_RULE_SETUP YY_RULE_SETUP
#line 523 "ncgen.l" #line 524 "ncgen.l"
{ {
byte_val = unescapehex(&ncgtext[3]); int hex = unescapehex(&ncgtext[3]);
if(byte_val < 0) { if(byte_val < 0) {
sprintf(errstr,"bad hex character constant: %s",(char*)ncgtext); sprintf(errstr,"bad hex character constant: %s",(char*)ncgtext);
yyerror(errstr); yyerror(errstr);
} }
byte_val = (unsigned int)hex;
return lexdebug(BYTE_CONST); return lexdebug(BYTE_CONST);
} }
YY_BREAK YY_BREAK
case 44: case 44:
YY_RULE_SETUP YY_RULE_SETUP
#line 531 "ncgen.l" #line 533 "ncgen.l"
{ {
switch ((char)ncgtext[2]) { switch ((char)ncgtext[2]) {
case 'a': byte_val = '\007'; break; /* not everyone under- case 'a': byte_val = '\007'; break; /* not everyone under-
@ -2044,7 +2046,7 @@ YY_RULE_SETUP
case 45: case 45:
/* rule 45 can match eol */ /* rule 45 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 549 "ncgen.l" #line 551 "ncgen.l"
{ {
lineno++ ; lineno++ ;
break; break;
@ -2052,7 +2054,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 46: case 46:
YY_RULE_SETUP YY_RULE_SETUP
#line 554 "ncgen.l" #line 556 "ncgen.l"
{/*initial*/ {/*initial*/
BEGIN(ST_C_COMMENT); BEGIN(ST_C_COMMENT);
break; break;
@ -2061,21 +2063,21 @@ YY_RULE_SETUP
case 47: case 47:
/* rule 47 can match eol */ /* rule 47 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 559 "ncgen.l" #line 561 "ncgen.l"
{/* continuation */ {/* continuation */
break; break;
} }
YY_BREAK YY_BREAK
case 48: case 48:
YY_RULE_SETUP YY_RULE_SETUP
#line 563 "ncgen.l" #line 565 "ncgen.l"
{/* final */ {/* final */
BEGIN(INITIAL); BEGIN(INITIAL);
break; break;
} }
YY_BREAK YY_BREAK
case YY_STATE_EOF(ST_C_COMMENT): case YY_STATE_EOF(ST_C_COMMENT):
#line 568 "ncgen.l" #line 570 "ncgen.l"
{/* final, error */ {/* final, error */
fprintf(stderr,"unterminated /**/ comment"); fprintf(stderr,"unterminated /**/ comment");
BEGIN(INITIAL); BEGIN(INITIAL);
@ -2084,17 +2086,17 @@ case YY_STATE_EOF(ST_C_COMMENT):
YY_BREAK YY_BREAK
case 49: case 49:
YY_RULE_SETUP YY_RULE_SETUP
#line 574 "ncgen.l" #line 576 "ncgen.l"
{/* Note: this next rule will not work for UTF8 characters */ {/* Note: this next rule will not work for UTF8 characters */
return lexdebug(ncgtext[0]) ; return lexdebug(ncgtext[0]) ;
} }
YY_BREAK YY_BREAK
case 50: case 50:
YY_RULE_SETUP YY_RULE_SETUP
#line 577 "ncgen.l" #line 579 "ncgen.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 2098 "lex.ncg.c" #line 2100 "lex.ncg.c"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(TEXT): case YY_STATE_EOF(TEXT):
yyterminate(); yyterminate();
@ -3093,7 +3095,7 @@ void ncgfree (void * ptr )
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
#line 577 "ncgen.l" #line 579 "ncgen.l"
static int static int