Skip to content

Commit

Permalink
Fix some initialization problem found with cppcheck.
Browse files Browse the repository at this point in the history
This patch adds a few missing initializations to various constructors
and reworks the realloc() error handling code in driver-vpi/main.c.
  • Loading branch information
caryr authored and steveicarus committed Oct 15, 2010
1 parent cb86fb1 commit eb525b6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 43 deletions.
13 changes: 9 additions & 4 deletions driver-vpi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion net_modulo.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions net_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion net_tran.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
68 changes: 32 additions & 36 deletions net_udp.cc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,7 +20,6 @@

# include "config.h"
# include "compiler.h"

# include "netlist.h"

NetUDP::NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp *u)
Expand All @@ -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:
return 'x';
}
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';
}
3 changes: 2 additions & 1 deletion synth.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit eb525b6

Please sign in to comment.