Fix some cppcheck warnings

This commit is contained in:
Cary R 2013-04-15 11:53:07 -07:00
parent 4c52f66f5d
commit fbafb915d2
14 changed files with 143 additions and 122 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002 Michael Ruff (mruff at chiaro.com)
* Copyright (c) 2002-2013 Michael Ruff (mruff at chiaro.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -27,7 +27,7 @@
char *mc_scan_plusargs(char *plusarg)
{
int argc, diff;
char **argv, *a, *p;
char **argv;
s_vpi_vlog_info vpi_vlog_info;
/* get command line */
@ -37,6 +37,7 @@ char *mc_scan_plusargs(char *plusarg)
/* for each argument */
argv = vpi_vlog_info.argv;
for (argc = 0; argc < vpi_vlog_info.argc; argc++, argv++) {
char *a, *p;
a = *argv;
p = plusarg;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2012 Michael Ruff (mruff at chiaro.com)
* Copyright (c) 2002-2013 Michael Ruff (mruff at chiaro.com)
* Michael Runyan (mrunyan at chiaro.com)
*
* This source code is free software; you can redistribute it
@ -78,9 +78,9 @@ void veriusertfs_register_table(p_tfcell vtable)
p_tfcell tf;
s_vpi_systf_data tf_data;
p_pli_data data;
static char trace_buf[1024];
if (!pli_trace && (path = getenv("PLI_TRACE"))) {
static char trace_buf[1024];
if (strcmp(path,"-") == 0)
pli_trace = stdout;
else {

View File

@ -830,7 +830,7 @@ int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
char *package_name = 0;
ivl_scope_type_t sc_type = ivl_scope_type(scope);
unsigned is_auto = ivl_scope_is_auto(scope);
unsigned idx, count;
unsigned idx;
/* Output the scope definition. */
switch (sc_type) {
@ -957,6 +957,7 @@ int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
emit_scope_variables(scope);
if (sc_type == IVL_SCT_MODULE) {
unsigned count;
/* Output the LPM devices. */
count = ivl_scope_lpms(scope);
for (idx = 0; idx < count; idx += 1) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -121,7 +121,6 @@ int number_is_immediate(ivl_expr_t expr, unsigned lim_wid, int negative_ok_flag)
long get_number_immediate(ivl_expr_t expr)
{
long imm = 0;
unsigned idx;
switch (ivl_expr_type(expr)) {
case IVL_EX_ULONG:
@ -131,6 +130,7 @@ long get_number_immediate(ivl_expr_t expr)
case IVL_EX_NUMBER: {
const char*bits = ivl_expr_bits(expr);
unsigned nbits = ivl_expr_width(expr);
unsigned idx;
/* We can not copy more bits than fit into a long. */
if (nbits > 8*sizeof(long)) nbits = 8*sizeof(long);
for (idx = 0 ; idx < nbits ; idx += 1) switch (bits[idx]){
@ -157,7 +157,6 @@ long get_number_immediate(ivl_expr_t expr)
uint64_t get_number_immediate64(ivl_expr_t expr)
{
uint64_t imm = 0;
unsigned idx;
switch (ivl_expr_type(expr)) {
case IVL_EX_ULONG:
@ -167,6 +166,7 @@ uint64_t get_number_immediate64(ivl_expr_t expr)
case IVL_EX_NUMBER: {
const char*bits = ivl_expr_bits(expr);
unsigned nbits = ivl_expr_width(expr);
unsigned idx;
for (idx = 0 ; idx < nbits ; idx += 1) switch (bits[idx]){
case '0':
break;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011,2013 Stephen Williams (steve@icarus.com)
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -482,8 +482,6 @@ static void set_vec_to_lval_slice(ivl_lval_t lval, unsigned bit, unsigned wid)
*/
static void set_vec_to_lval(ivl_statement_t net, struct vector_info res)
{
ivl_lval_t lval;
unsigned wid = res.wid;
unsigned lidx;
unsigned cur_rbit = 0;
@ -492,7 +490,7 @@ static void set_vec_to_lval(ivl_statement_t net, struct vector_info res)
unsigned bidx;
unsigned bit_limit = wid - cur_rbit;
lval = ivl_stmt_lval(net, lidx);
ivl_lval_t lval = ivl_stmt_lval(net, lidx);
/* Reduce bit_limit to the width of this l-value. */
if (bit_limit > ivl_lval_width(lval))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -2037,7 +2037,6 @@ static int show_statement(ivl_statement_t net, ivl_scope_t sscope)
{
const ivl_statement_type_t code = ivl_statement_type(net);
int rc = 0;
unsigned saved_file_line = 0;
switch (code) {
@ -2057,6 +2056,7 @@ static int show_statement(ivl_statement_t net, ivl_scope_t sscope)
if (ivl_stmt_block_scope(net))
rc += show_stmt_block_named(net, sscope);
else {
unsigned saved_file_line = 0;
/* This block could really represent a single statement.
* If so only emit a single %file_line opcode. */
if (show_file_line) {

View File

@ -4,34 +4,63 @@
// fstapi.c from GTKWave
obsoleteFunctionsasctime:fstapi.c:652
variableScope:fstapi.c:751
variableScope:fstapi.c:1707
variableScope:fstapi.c:1965
variableScope:fstapi.c:2109
variableScope:fstapi.c:2268
variableScope:fstapi.c:2269
variableScope:fstapi.c:2828
variableScope:fstapi.c:2853
variableScope:fstapi.c:2976
variableScope:fstapi.c:3304
variableScope:fstapi.c:3313
variableScope:fstapi.c:3815
variableScope:fstapi.c:3818
variableScope:fstapi.c:4385
variableScope:fstapi.c:4439
variableScope:fstapi.c:4743
variableScope:fstapi.c:4746
variableScope:fstapi.c:4982
variableScope:fstapi.c:5087
variableScope:fstapi.c:5088
variableScope:fstapi.c:5119
// lxt2_write.c from GTKWave
obsoleteFunctionsalloca:lxt2_write.c:1813
obsoleteFunctionsalloca:lxt2_write.c:1819
variableScope:lxt2_write.c:33
variableScope:lxt2_write.c:63
variableScope:lxt2_write.c:196
variableScope:lxt2_write.c:463
variableScope:lxt2_write.c:464
variableScope:lxt2_write.c:523
variableScope:lxt2_write.c:581
variableScope:lxt2_write.c:587
variableScope:lxt2_write.c:1157
variableScope:lxt2_write.c:1613
variableScope:lxt2_write.c:2060
// lxt_write.c from GTKWave
variableScope:lxt_write.c:31
variableScope:lxt_write.c:83
variableScope:lxt_write.c:527
variableScope:lxt_write.c:528
variableScope:lxt_write.c:587
variableScope:lxt_write.c:640
variableScope:lxt_write.c:780
variableScope:lxt_write.c:880
variableScope:lxt_write.c:1056
variableScope:lxt_write.c:1057
variableScope:lxt_write.c:1058
variableScope:lxt_write.c:1194
variableScope:lxt_write.c:1850
variableScope:lxt_write.c:2029
variableScope:lxt_write.c:2030
variableScope:lxt_write.c:2147
variableScope:lxt_write.c:2148
variableScope:lxt_write.c:2265
variableScope:lxt_write.c:2266
variableScope:lxt_write.c:2595
variableScope:lxt_write.c:2596
variableScope:lxt_write.c:2597

View File

@ -1,4 +1,3 @@
/*
* NOTE: This code as been slightly modified to interface with the
* PLI implementations of $random. The copyright and license
@ -84,13 +83,13 @@ unsigned long
genrand(struct context_s *context)
{
unsigned long y;
static unsigned long mag01[2]={0x0, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
unsigned long *mt = context->mt;
int mti = context->mti;
if (mti >= N) { /* generate N words at one time */
/* mag01[x] = x * MATRIX_A for x=0,1 */
static unsigned long mag01[2]={0x0, MATRIX_A};
int kk;
if (mti == N+1) /* if sgenrand() has not been called, */
@ -120,4 +119,3 @@ genrand(struct context_s *context)
return y;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2012 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -535,12 +535,10 @@ static PLI_INT32 sys_fread_compiletf(ICARUS_VPI_CONST PLI_BYTE8*name)
static unsigned fread_word(FILE *fp, vpiHandle word,
unsigned words, unsigned bpe, s_vpi_vecval *vector)
{
unsigned rtn, clr_mask, bnum;
int bidx, byte;
int bidx;
s_vpi_value val;
struct t_vpi_vecval *cur = &vector[words-1];
rtn = 0;
unsigned rtn = 0;
/* Get the current bits from the register and copy them to
* my local vector. */
@ -553,7 +551,8 @@ static unsigned fread_word(FILE *fp, vpiHandle word,
/* Copy the bytes to the local vector MSByte first. */
for (bidx = bpe-1; bidx >= 0; bidx -= 1) {
byte = fgetc(fp);
unsigned clr_mask, bnum;
int byte = fgetc(fp);
if (byte == EOF) break;
/* Clear the current byte and load the new value. */
bnum = bidx % 4;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -479,24 +479,6 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
unsigned size;
PLI_INT32 item_type;
/* list of types to iterate upon */
int i;
static int types[] = {
/* Value */
vpiNamedEvent,
vpiNet,
// vpiParameter,
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
/* Get the displayed type for the various $var and $scope types. */
/* Not all of these are supported now, but they should be in a
* future development version. */
@ -667,8 +649,25 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
case vpiNamedFork:
if (depth > 0) {
int nskip = (vcd_names_search(&fst_tab, fullname) != 0);
char *defname = NULL;
/* list of types to iterate upon */
static int types[] = {
/* Value */
vpiNamedEvent,
vpiNet,
/* vpiParameter, */
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
int i;
int nskip = (vcd_names_search(&fst_tab, fullname) != 0);
/* We have to always scan the scope because the
* depth could be different for this call. */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2011 Stephen Williams (steve@icarus.com)
* Copyright (c) 2002-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -528,22 +528,6 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
const char* ident;
int nexus_id;
/* list of types to iterate upon */
int i;
static int types[] = {
/* Value */
vpiNet,
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
switch (vpi_get(vpiType, item)) {
case vpiMemoryWord:
@ -662,23 +646,37 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
case vpiNamedFork:
if (depth > 0) {
int nskip;
vpiHandle argv;
const char* fullname =
vpi_get_str(vpiFullName, item);
const char* fullname = vpi_get_str(vpiFullName, item);
/* list of types to iterate upon */
static int types[] = {
/* Value */
/* vpiNamedEvent, */
vpiNet,
/* vpiParameter, */
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
int i;
int nskip = (vcd_names_search(&lxt_tab, fullname) != 0);
#if 0
vpi_printf("LXT info: scanning scope %s, %u levels\n",
fullname, depth);
#endif
nskip = 0 != vcd_names_search(&lxt_tab, fullname);
if (!nskip)
if (nskip) {
vpi_printf("LXT warning: ignoring signals in "
"previously scanned scope %s\n", fullname);
} else {
vcd_names_add(&lxt_tab, fullname);
else
vpi_printf("LXT warning: ignoring signals in "
"previously scanned scope %s\n", fullname);
}
name = vpi_get_str(vpiName, item);
@ -686,7 +684,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
for (i=0; types[i]>0; i++) {
vpiHandle hand;
argv = vpi_iterate(types[i], item);
vpiHandle argv = vpi_iterate(types[i], item);
while (argv && (hand = vpi_scan(argv))) {
scan_item(depth-1, hand, nskip);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2011 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -591,22 +591,6 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
const char* ident;
int nexus_id;
/* list of types to iterate upon */
int i;
static int types[] = {
/* Value */
vpiNet,
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
switch (vpi_get(vpiType, item)) {
case vpiMemoryWord:
@ -717,23 +701,37 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
case vpiNamedFork:
if (depth > 0) {
int nskip;
vpiHandle argv;
const char* fullname =
vpi_get_str(vpiFullName, item);
const char* fullname = vpi_get_str(vpiFullName, item);
/* list of types to iterate upon */
static int types[] = {
/* Value */
/* vpiNamedEvent, */
vpiNet,
/* vpiParameter, */
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
int i;
int nskip = vcd_scope_names_test(fullname);
#if 0
vpi_printf("LXT2 info: scanning scope %s, %u levels\n",
fullname, depth);
#endif
nskip = vcd_scope_names_test(fullname);
if (!nskip)
if (nskip) {
vpi_printf("LXT2 warning: ignoring signals in "
"previously scanned scope %s\n", fullname);
} else {
vcd_scope_names_add(fullname);
else
vpi_printf("LXT2 warning: ignoring signals in "
"previously scanned scope %s\n", fullname);
}
name = vpi_get_str(vpiName, item);
@ -741,7 +739,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
for (i=0; types[i]>0; i++) {
vpiHandle hand;
argv = vpi_iterate(types[i], item);
vpiHandle argv = vpi_iterate(types[i], item);
while (argv && (hand = vpi_scan(argv))) {
scan_item(depth-1, hand, nskip);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2012 Stephen Williams (steve@icarus.com)
* Copyright (c) 2006-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -469,7 +469,6 @@ static int scan_format_decimal(vpiHandle callh, vpiHandle argv,
{
vpiHandle arg;
char *strval = malloc(1);
unsigned len = 0;
s_vpi_value val;
int ch;
@ -495,6 +494,7 @@ static int scan_format_decimal(vpiHandle callh, vpiHandle argv,
strval[0] = 'z';
strval[1] = 0;
} else {
unsigned len = 0;
/* To match a + or - we must have a digit after it. */
if (ch == '+') {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2013 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -85,13 +85,14 @@ static void gen_new_vcd_id(void)
static char *truncate_bitvec(char *s)
{
char l, r;
char r;
r=*s;
if(r=='1') return s;
else s += 1;
for(;;s++) {
char l;
l=r; r=*s;
if(!r) return (s-1);
if(l!=r) return(((l=='0')&&(r=='1'))?s:s-1);
@ -508,24 +509,6 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
unsigned size;
PLI_INT32 item_type;
/* list of types to iterate upon */
int i;
static int types[] = {
/* Value */
vpiNamedEvent,
vpiNet,
// vpiParameter,
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
/* Get the displayed type for the various $var and $scope types. */
/* Not all of these are supported now, but they should be in a
* future development version. */
@ -690,6 +673,23 @@ static void scan_item(unsigned depth, vpiHandle item, int skip)
case vpiNamedFork:
if (depth > 0) {
/* list of types to iterate upon */
static int types[] = {
/* Value */
vpiNamedEvent,
vpiNet,
/* vpiParameter, */
vpiReg,
vpiVariables,
/* Scope */
vpiFunction,
vpiModule,
vpiNamedBegin,
vpiNamedFork,
vpiTask,
-1
};
int i;
int nskip = (vcd_names_search(&vcd_tab, fullname) != 0);
/* We have to always scan the scope because the