Permalink
Browse files

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.
  • Loading branch information...
1 parent cb86fb1 commit eb525b6c2a91fe73b8f9d5d03c205bf575238dd1 @caryr caryr committed with steveicarus Oct 10, 2010
Showing with 52 additions and 43 deletions.
  1. +9 −4 driver-vpi/main.c
  2. +2 −1 net_modulo.cc
  3. +3 −0 net_scope.cc
  4. +4 −1 net_tran.cc
  5. +32 −36 net_udp.cc
  6. +2 −1 synth.cc
View
13 driver-vpi/main.c
@@ -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
3 net_modulo.cc
@@ -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
3 net_scope.cc
@@ -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
5 net_tran.cc
@@ -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
68 net_udp.cc
@@ -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:
- 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';
}
View
3 synth.cc
@@ -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:

0 comments on commit eb525b6

Please sign in to comment.