Fix some initialization problem found with cppcheck.

This patch adds a few missing initializations to various constructors
and reworks the realloc() error handling code in driver-vpi/main.c.
This commit is contained in:
Cary R 2010-10-09 21:35:57 -07:00 committed by Stephen Williams
parent cb86fb15bf
commit eb525b6c2a
6 changed files with 52 additions and 43 deletions

View File

@ -154,12 +154,15 @@ static int startsWith (char *prefix, char *str)
static void appendn (char **ptr, char *app, int count)
{
*ptr = (char *) realloc(*ptr,strlen(*ptr)+(count?count:strlen(app))+1);
char *nptr = (char *) realloc(*ptr, strlen(*ptr) +
(count?count:strlen(app)) + 1);
if (*ptr == NULL) {
if (nptr == NULL) {
fprintf(stderr,"error: out of memory\n");
free(*ptr);
myExit(4);
}
*ptr = nptr;
if (count)
strncat(*ptr,app,count);
@ -187,12 +190,14 @@ static void appendBackSlash(char **str)
static void assignn (char **ptr, char *str, int count)
{
*ptr = (char *) realloc(*ptr,(count?count:strlen(str))+1);
char *nptr = (char *) realloc(*ptr, (count?count:strlen(str)) + 1);
if (*ptr == NULL) {
if (nptr == NULL) {
fprintf(stderr,"error: out of memory\n");
free(*ptr);
myExit(4);
}
*ptr = nptr;
if (count) {
strncpy(*ptr,str,count);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2010 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
@ -40,6 +40,7 @@ NetModulo::NetModulo(NetScope*s, perm_string n, unsigned wr,
pin(0).set_dir(Link::OUTPUT); // Result
pin(1).set_dir(Link::INPUT); // DataA
pin(2).set_dir(Link::INPUT); // DataB
signed_flag_ = false;
}
NetModulo::~NetModulo()

View File

@ -69,6 +69,9 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t)
default: /* BEGIN_END and FORK_JOIN, do nothing */
break;
}
lineno_ = 0;
def_lineno_ = 0;
genvar_tmp_val = 0;
}
NetScope::~NetScope()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2008-2010 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
@ -50,6 +50,9 @@ NetTran::NetTran(NetScope*scope__, perm_string n, ivl_switch_type_t tt)
if (pin_count() == 3) {
pin(2).set_dir(Link::INPUT); // Enable
}
wid_ = 0;
part_ = 0;
off_ = 0;
}
NetTran::NetTran(NetScope*scope__, perm_string n, unsigned wid, unsigned part, unsigned off)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
*
* This source code is free software; you can redistribute it
@ -20,7 +20,6 @@
# include "config.h"
# include "compiler.h"
# include "netlist.h"
NetUDP::NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp *u)
@ -30,56 +29,53 @@ NetUDP::NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp *u)
for (unsigned idx = 1 ; idx < pins ; idx += 1) {
pin(idx).set_dir(Link::INPUT);
}
table_idx = udp->tinput.count()-1;
}
bool NetUDP::first(string&inp, char&out) const
{
table_idx = (unsigned) -1;
return next(inp, out);
table_idx = (unsigned) -1;
return next(inp, out);
}
bool NetUDP::next(string&inp, char&out) const
{
table_idx++;
table_idx++;
if (table_idx >= udp->tinput.count())
return false;
if (table_idx >= udp->tinput.count()) return false;
if (is_sequential())
{
inp = string("") + udp->tcurrent[table_idx] + udp->tinput[table_idx];
assert(inp.length() == pin_count());
}
else
{
inp = udp->tinput[table_idx];
assert(inp.length() == (pin_count()-1));
}
if (is_sequential()) {
inp = string("") + udp->tcurrent[table_idx] +
udp->tinput[table_idx];
assert(inp.length() == pin_count());
} else {
inp = udp->tinput[table_idx];
assert(inp.length() == (pin_count()-1));
}
out = udp->toutput[table_idx];
assert( (out == '0')
|| (out == '1')
|| (out == 'x')
|| (is_sequential() && (out == '-')));
out = udp->toutput[table_idx];
assert((out == '0') ||
(out == '1') ||
(out == 'x') ||
(is_sequential() && (out == '-')));
return true;
return true;
}
char NetUDP::get_initial() const
{
assert (is_sequential());
assert (is_sequential());
switch (udp->initial)
{
case verinum::V0:
return '0';
case verinum::V1:
return '1';
case verinum::Vx:
case verinum::Vz:
switch (udp->initial) {
case verinum::V0:
return '0';
case verinum::V1:
return '1';
case verinum::Vx:
case verinum::Vz:
return 'x';
}
assert(0);
return 'x';
}
assert(0);
return 'x';
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2010 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
@ -113,6 +113,7 @@ int do_expr::event_wait(NetEvWait*stmt)
class synth_f : public functor_t {
public:
synth_f() { top_ = NULL; }
void process(class Design*, class NetProcTop*);
private: