Addressed some instances of Coverity issue 711927, uninitialized scalar variable.

Modified 'makeparser' target in CMake build system.
This commit is contained in:
Ward Fisher 2013-08-14 10:12:49 -06:00
parent f51f97546b
commit 4980b9f4e1
5 changed files with 227 additions and 257 deletions

View File

@ -46,6 +46,10 @@ ADD_CUSTOM_COMMAND(
COMMAND rm -f ncgentab.c ncgentab.h
COMMAND mv ncgen.tab.c ncgentab.c
COMMAND mv ncgen.tab.h ncgentab.h
COMMAND mv ncgentab.h ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND mv ncgentab.c ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND mv ncgenyy.c ${CMAKE_CURRENT_SOURCE_DIR}
)
ADD_CUSTOM_TARGET(makeparser DEPENDS ncgentab.h)

View File

@ -97,9 +97,9 @@ List* condefs; /* non-dimension constants used in type defs*/
List* tmp;
/* Forward */
static Constant makeconstdata(nc_type);
static Constant evaluate(Symbol* fcn, Datalist* arglist);
static Constant makeenumconst(Symbol*);
static NCConstant makeconstdata(nc_type);
static NCConstant evaluate(Symbol* fcn, Datalist* arglist);
static NCConstant makeenumconst(Symbol*);
static void addtogroup(Symbol*);
static Symbol* currentgroup(void);
static Symbol* createrootgroup(void);
@ -110,7 +110,7 @@ static Symbol* makeattribute(Symbol*,Symbol*,Symbol*,Datalist*,Attrkind);
static Symbol* makeprimitivetype(nc_type i);
static Symbol* makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst);
static int containsfills(Datalist* list);
static void datalistextend(Datalist* dl, Constant* con);
static void datalistextend(Datalist* dl, NCConstant* con);
static void vercheck(int ncid);
int yylex(void);
@ -134,7 +134,7 @@ unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/
long mark; /* track indices into the sequence*/
int nctype; /* for tracking attribute list type*/
Datalist* datalist;
Constant constant;
NCConstant constant;
}
%token <sym>
@ -998,10 +998,10 @@ creategroup(Symbol * gsym)
return gsym;
}
static Constant
static NCConstant
makeconstdata(nc_type nctype)
{
Constant con = nullconstant;
NCConstant con = nullconstant;
consttype = nctype;
con.nctype = nctype;
con.lineno = lineno;
@ -1061,10 +1061,10 @@ makeconstdata(nc_type nctype)
return con;
}
static Constant
static NCConstant
makeenumconst(Symbol* econst)
{
Constant con;
NCConstant con;
markcdf4("Enum type");
consttype = NC_ENUM;
con.nctype = NC_ECONST;
@ -1143,7 +1143,7 @@ specialname(int flag)
}
static int
truefalse(Constant* con, int tag)
truefalse(NCConstant* con, int tag)
{
if(con->nctype == NC_STRING) {
char* sdata = con->value.stringv.stringv;
@ -1172,22 +1172,24 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst)
{
Symbol* attr = NULL;
Datalist* list;
Constant* con;
NCConstant* con;
Specialdata* special = (Specialdata*)malloc(sizeof(Specialdata));
Constant iconst;
NCConstant iconst;
int tf = 0;
char* sdata = NULL;
int idata = -1;
special->flags = 0;
specials_flag += (tag == _FILLVALUE_FLAG ? 0 : 1);
if(isconst) {
con = (Constant*)data;
con = (NCConstant*)data;
list = builddatalist(1);
dlappend(list,(Constant*)data);
dlappend(list,(NCConstant*)data);
} else {
list = (Datalist*)data;
con = (Constant*)list->data;
con = (NCConstant*)list->data;
}
if(tag == _FORMAT && vsym != NULL) {
@ -1355,7 +1357,7 @@ containsfills(Datalist* list)
{
if(list != NULL) {
int i;
Constant* con = list->data;
NCConstant* con = list->data;
for(i=0;i<list->length;i++,con++) {
if(con->nctype == NC_COMPOUND) {
if(containsfills(con->value.compoundv)) return 1;
@ -1366,7 +1368,7 @@ containsfills(Datalist* list)
}
static void
datalistextend(Datalist* dl, Constant* con)
datalistextend(Datalist* dl, NCConstant* con)
{
dlappend(dl,con);
}
@ -1399,10 +1401,10 @@ Note that currently, only a single value can
be returned.
*/
static Constant
static NCConstant
evaluate(Symbol* fcn, Datalist* arglist)
{
Constant result;
NCConstant result;
/* prepare the result */
result.lineno = fcn->lineno;

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 2.7.12-4996. */
/* 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
it under the terms of the GNU General Public License as published by
@ -101,7 +101,7 @@ extern int ncgdebug;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 2077 of yacc.c */
/* Line 2053 of yacc.c */
#line 131 "ncgen.y"
Symbol* sym;
@ -109,10 +109,10 @@ unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/
long mark; /* track indices into the sequence*/
int nctype; /* for tracking attribute list type*/
Datalist* datalist;
Constant constant;
NCConstant constant;
/* Line 2077 of yacc.c */
/* Line 2053 of yacc.c */
#line 117 "ncgen.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1

View File

@ -27,7 +27,7 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 35
#define YY_FLEX_SUBMINOR_VERSION 37
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@ -72,7 +72,6 @@ typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@ -103,6 +102,8 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@ -171,7 +172,12 @@ typedef unsigned int flex_uint32_t;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
extern int ncgleng;
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
extern yy_size_t ncgleng;
extern FILE *ncgin, *ncgout;
@ -197,11 +203,6 @@ extern FILE *ncgin, *ncgout;
#define unput(c) yyunput( c, (yytext_ptr) )
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
@ -219,7 +220,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
@ -289,8 +290,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
/* yy_hold_char holds the character lost when ncgtext is formed. */
static char yy_hold_char;
static int yy_n_chars; /* number of characters read into yy_ch_buf */
int ncgleng;
static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
yy_size_t ncgleng;
/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
@ -318,7 +319,7 @@ static void ncg_init_buffer (YY_BUFFER_STATE b,FILE *file );
YY_BUFFER_STATE ncg_scan_buffer (char *base,yy_size_t size );
YY_BUFFER_STATE ncg_scan_string (yyconst char *yy_str );
YY_BUFFER_STATE ncg_scan_bytes (yyconst char *bytes,int len );
YY_BUFFER_STATE ncg_scan_bytes (yyconst char *bytes,yy_size_t len );
void *ncgalloc (yy_size_t );
void *ncgrealloc (void *,yy_size_t );
@ -1224,7 +1225,7 @@ ID ([A-Za-z_]|{UTF8})([A-Z.@#\[\]a-z_0-9+-]|{UTF8})*
/* Note: this definition of string will work for utf8 as well,
although it is a very relaxed definition
*/
#line 1228 "lex.ncg.c"
#line 1229 "lex.ncg.c"
#define INITIAL 0
#define ST_C_COMMENT 1
@ -1265,7 +1266,7 @@ FILE *ncgget_out (void );
void ncgset_out (FILE * out_str );
int ncgget_leng (void );
yy_size_t ncgget_leng (void );
char *ncgget_text (void );
@ -1326,7 +1327,7 @@ static int input (void );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
unsigned n; \
size_t n; \
for ( n = 0; n < max_size && \
(c = getc( ncgin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@ -1410,7 +1411,7 @@ YY_DECL
#line 168 "ncgen.l"
#line 1414 "lex.ncg.c"
#line 1415 "lex.ncg.c"
if ( !(yy_init) )
{
@ -2072,7 +2073,7 @@ YY_RULE_SETUP
#line 563 "ncgen.l"
ECHO;
YY_BREAK
#line 2076 "lex.ncg.c"
#line 2077 "lex.ncg.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(TEXT):
yyterminate();
@ -2259,21 +2260,21 @@ static int yy_get_next_buffer (void)
else
{
int num_to_read =
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
@ -2304,7 +2305,7 @@ static int yy_get_next_buffer (void)
/* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
(yy_n_chars), (size_t) num_to_read );
(yy_n_chars), num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
@ -2414,7 +2415,7 @@ static int yy_get_next_buffer (void)
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
register int number_to_move = (yy_n_chars) + 2;
register yy_size_t number_to_move = (yy_n_chars) + 2;
register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char *source =
@ -2463,7 +2464,7 @@ static int yy_get_next_buffer (void)
else
{ /* need more input */
int offset = (yy_c_buf_p) - (yytext_ptr);
yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
++(yy_c_buf_p);
switch ( yy_get_next_buffer( ) )
@ -2623,10 +2624,6 @@ static void ncg_load_buffer_state (void)
ncgfree((void *) b );
}
#ifndef __cplusplus
extern int isatty (int );
#endif /* __cplusplus */
/* Initializes or reinitializes a buffer.
* This function is sometimes called more than once on the same buffer,
* such as during a ncgrestart() or at EOF.
@ -2739,7 +2736,7 @@ void ncgpop_buffer_state (void)
*/
static void ncgensure_buffer_stack (void)
{
int num_to_alloc;
yy_size_t num_to_alloc;
if (!(yy_buffer_stack)) {
@ -2831,12 +2828,12 @@ YY_BUFFER_STATE ncg_scan_string (yyconst char * yystr )
/** Setup the input buffer state to scan the given bytes. The next call to ncglex() will
* scan from a @e copy of @a bytes.
* @param bytes the byte buffer to scan
* @param len the number of bytes in the buffer pointed to by @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
*
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE ncg_scan_bytes (yyconst char * yybytes, int _yybytes_len )
YY_BUFFER_STATE ncg_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
{
YY_BUFFER_STATE b;
char *buf;
@ -2923,7 +2920,7 @@ FILE *ncgget_out (void)
/** Get the length of the current token.
*
*/
int ncgget_leng (void)
yy_size_t ncgget_leng (void)
{
return ncgleng;
}