Skip to content
Browse files

Add error checking definitions for malloc(), realloc() and calloc()

This patch adds defines that translate all malloc(), realloc() and calloc()
calls into ones with error checking when ivl_alloc.h is included.
  • Loading branch information...
1 parent 93f8453 commit cb86fb15bf96b2634c117d433853f8899b96e42a @caryr caryr committed with steveicarus Oct 9, 2010
Showing with 168 additions and 89 deletions.
  1. +1 −0 StringHeap.cc
  2. +1 −0 cadpli/cadpli.c
  3. +3 −1 driver/main.c
  4. +1 −0 driver/substit.c
  5. +86 −0 ivl_alloc.h
  6. +4 −3 ivlpp/lexor.lex
  7. +1 −0 ivlpp/main.c
  8. +1 −0 libveriuser/a_vcl.c
  9. +1 −2 libveriuser/veriusertfs.c
  10. +1 −0 libveriuser/workarea.c
  11. +1 −0 load_module.cc
  12. +1 −0 main.cc
  13. +1 −0 net_link.cc
  14. +1 −0 pform.cc
  15. +1 −1 t-dll-analog.cc
  16. +1 −0 t-dll-api.cc
  17. +1 −10 t-dll-expr.cc
  18. +1 −3 t-dll-proc.cc
  19. +6 −3 t-dll.cc
  20. +1 −0 tgt-fpga/d-generic-edif.c
  21. +1 −0 tgt-fpga/edif.c
  22. +1 −0 tgt-fpga/mangle.c
  23. +1 −0 tgt-fpga/xilinx.c
  24. +1 −0 tgt-pal/emit_jed.c
  25. +2 −28 tgt-pal/fit_log.c
  26. +1 −1 tgt-pal/imain.c
  27. +1 −0 tgt-stub/stub.c
  28. +1 −1 tgt-vvp/draw_net_input.c
  29. +1 −0 tgt-vvp/draw_vpi.c
  30. +1 −0 tgt-vvp/eval_expr.c
  31. +1 −0 tgt-vvp/modpath.c
  32. +1 −3 tgt-vvp/vvp_scope.c
  33. +1 −0 vpi/sdf_parse.y
  34. +1 −0 vpi/stringheap.c
  35. +1 −0 vpi/sys_display.c
  36. +1 −0 vpi/sys_fileio.c
  37. +1 −0 vpi/sys_fst.c
  38. +1 −0 vpi/sys_lxt.c
  39. +1 −0 vpi/sys_lxt2.c
  40. +1 −0 vpi/sys_priv.c
  41. +1 −1 vpi/sys_random_mti.c
  42. +1 −0 vpi/sys_readmem.c
  43. +1 −0 vpi/sys_scanf.c
  44. +1 −0 vpi/sys_vcd.c
  45. +1 −12 vpi/v2005_math.c
  46. +1 −12 vpi/va_math.c
  47. +1 −2 vpi/vcd_priv.c
  48. +1 −0 vvp/array.cc
  49. +1 −0 vvp/compile.cc
  50. +1 −0 vvp/delay.cc
  51. +1 −1 vvp/lexor.lex
  52. +1 −0 vvp/parse.y
  53. +1 −0 vvp/parse_misc.cc
  54. +1 −0 vvp/stop.cc
  55. +1 −0 vvp/udp.cc
  56. +1 −0 vvp/vpi_const.cc
  57. +1 −0 vvp/vpi_event.cc
  58. +1 −0 vvp/vpi_iter.cc
  59. +1 −0 vvp/vpi_mcd.cc
  60. +2 −1 vvp/vpi_modules.cc
  61. +1 −0 vvp/vpi_real.cc
  62. +1 −0 vvp/vpi_scope.cc
  63. +1 −0 vvp/vpi_signal.cc
  64. +1 −0 vvp/vpi_tasks.cc
  65. +1 −0 vvp/vpi_vthr_vector.cc
  66. +2 −3 vvp/vpip_to_dec.cc
  67. +1 −0 vvp/vvp_island.cc
  68. +2 −1 vvp/vvp_net.cc
  69. +1 −0 vvp/vvp_net.h
View
1 StringHeap.cc
@@ -18,6 +18,7 @@
*/
# include "StringHeap.h"
+# include "ivl_alloc.h"
# include <cstdlib>
# include <cstring>
# include <cassert>
View
1 cadpli/cadpli.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+# include "ivl_alloc.h"
# include <vpi_user.h>
# include <veriuser.h>
# include <stdlib.h>
View
4 driver/main.c
@@ -50,6 +50,7 @@ const char HELP[] =
#define MAXSIZE 4096
+#include "ivl_alloc.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@@ -886,7 +887,8 @@ int main(int argc, char **argv)
break;
case 'P':
defparm_size += 1;
- defparm_base = (const char**)realloc(defparm_base, defparm_size*sizeof(char*));
+ defparm_base = (const char**)realloc(defparm_base,
+ defparm_size*sizeof(char*));
defparm_base[defparm_size-1] = optarg;
break;
case 'p':
View
1 driver/substit.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
# include <stdio.h>
View
86 ivl_alloc.h
@@ -0,0 +1,86 @@
+#ifndef __ivl_alloc_H
+#define __ivl_alloc_H
+/*
+ * Copyright (C) 2010 Cary R. (cygcary@yahoo.com)
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef __cplusplus
+# include <cstdlib>
+# include <cstdio>
+#else
+# include <stdlib.h>
+# include <stdio.h>
+#endif
+
+/*
+ * Define a safer version of malloc().
+ */
+
+#define malloc(__ivl_size) \
+({ \
+ /* To be safe we only evaluate the argument once. */ \
+ size_t __ivl_lsize = __ivl_size; \
+ void *__ivl_rtn = malloc(__ivl_lsize); \
+ /* If we run out of memory then exit with a message. */ \
+ if ((__ivl_rtn == NULL) && (__ivl_lsize != 0)) { \
+ fprintf(stderr, "%s:%d: Error: malloc() ran out of memory.\n", \
+ __FILE__, __LINE__); \
+ exit(1); \
+ } \
+ __ivl_rtn; \
+})
+
+/*
+ * Define a safer version of realloc().
+ */
+
+#define realloc(__ivl_ptr, __ivl_size) \
+({ \
+ /* To be safe we only evaluate the arguments once. */ \
+ void *__ivl_lptr = __ivl_ptr; \
+ size_t __ivl_lsize = __ivl_size; \
+ void *__ivl_rtn = realloc(__ivl_lptr, __ivl_lsize); \
+ /* If we run out of memory then exit with a message. */ \
+ if ((__ivl_rtn == NULL) && (__ivl_lsize != 0)) { \
+ fprintf(stderr, "%s:%d: Error: realloc() ran out of memory.\n", \
+ __FILE__, __LINE__); \
+ free(__ivl_lptr); \
+ exit(1); \
+ } \
+ __ivl_rtn; \
+})
+
+/*
+ * Define a safer version of calloc().
+ */
+
+#define calloc(__ivl_count, __ivl_size) \
+({ \
+ /* To be safe we only evaluate the arguments once. */ \
+ size_t __ivl_lcount = __ivl_count; \
+ size_t __ivl_lsize = __ivl_size; \
+ void *__ivl_rtn = calloc(__ivl_lcount, __ivl_lsize); \
+ /* If we run out of memory then exit with a message. */ \
+ if ((__ivl_rtn == NULL) && (__ivl_lcount != 0) && (__ivl_lsize != 0)) { \
+ fprintf(stderr, "%s:%d: Error: calloc() ran out of memory.\n", \
+ __FILE__, __LINE__); \
+ exit(1); \
+ } \
+ __ivl_rtn; \
+})
+
+#endif
View
7 ivlpp/lexor.lex
@@ -20,6 +20,7 @@
# include "config.h"
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
@@ -977,7 +978,7 @@ static void do_define()
}
/* Accumulate this text into the define_text string. */
- define_text = realloc(define_text, define_cnt + (cp-yytext) + 1); assert(define_text != 0);
+ define_text = realloc(define_text, define_cnt + (cp-yytext) + 1);
head = &define_text[define_cnt];
strcpy(head, yytext);
@@ -1023,7 +1024,7 @@ static void do_define()
char* base = define_text;
define_cnt += added_cnt;
- define_text = realloc(define_text, define_cnt + 1); assert(define_text != 0);
+ define_text = realloc(define_text, define_cnt + 1);
head = &define_text[head - base];
tail = &define_text[tail - base];
@@ -1280,7 +1281,7 @@ static void exp_buf_grow_to_fit(int length)
{
exp_buf_size += EXP_BUF_CHUNK;
exp_buf_free += EXP_BUF_CHUNK;
- exp_buf = realloc(exp_buf, exp_buf_size); assert(exp_buf != 0);
+ exp_buf = realloc(exp_buf, exp_buf_size);
}
}
View
1 ivlpp/main.c
@@ -37,6 +37,7 @@ const char NOTICE[] =
" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
;
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
View
1 libveriuser/a_vcl.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+#include "ivl_alloc.h"
#include <vpi_user.h>
#include <acc_user.h>
#include <stdlib.h>
View
3 libveriuser/veriusertfs.c
@@ -23,6 +23,7 @@
* via VPI. This is extremely ugly, so don't look after eating dinner.
*/
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
# include <assert.h>
@@ -104,7 +105,6 @@ void veriusertfs_register_table(p_tfcell vtable)
/* squirrel away veriusertfs in persistent user_data */
data = calloc(1, sizeof(s_pli_data));
- assert(data != NULL);
udata_count += 1;
udata_store = (p_pli_data*)realloc(udata_store,
udata_count*sizeof(p_pli_data*));
@@ -222,7 +222,6 @@ static PLI_INT32 compiletf(char *data)
while ((arg_h = vpi_scan(arg_i)) != NULL) {
/* replicate user_data for each instance */
dp = calloc(1, sizeof(s_pli_data));
- assert(dp != NULL);
memcpy(dp, cb_data.user_data, sizeof(s_pli_data));
dp->paramvc = paramvc++;
cb_data.user_data = (char *)dp;
View
1 libveriuser/workarea.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+# include "ivl_alloc.h"
# include <veriuser.h>
# include <vpi_user.h>
# include <stdlib.h>
View
1 load_module.cc
@@ -21,6 +21,7 @@
# include "util.h"
# include "parse_api.h"
# include "compiler.h"
+# include "ivl_alloc.h"
# include <iostream>
# include <map>
# include <cstdlib>
View
1 main.cc
@@ -38,6 +38,7 @@ const char NOTICE[] =
" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
;
+# include "ivl_alloc.h"
# include <cstdio>
# include <iostream>
# include <fstream>
View
1 net_link.cc
@@ -22,6 +22,7 @@
# include <iostream>
# include "netlist.h"
+# include "ivl_alloc.h"
# include <sstream>
# include <cstring>
# include <string>
View
1 pform.cc
@@ -28,6 +28,7 @@
# include "PGenerate.h"
# include "PSpec.h"
# include "discipline.h"
+# include "ivl_alloc.h"
# include <list>
# include <map>
# include <cassert>
View
2 t-dll-analog.cc
@@ -22,6 +22,7 @@
# include <iostream>
+# include "ivl_alloc.h"
# include <cstring>
# include "target.h"
# include "ivl_target.h"
@@ -49,7 +50,6 @@ bool dll_target::process(const NetAnalogTop*net)
assert(stmt_cur_ == 0);
stmt_cur_ = (struct ivl_statement_s*)calloc(1, sizeof*stmt_cur_);
- assert(stmt_cur_);
rc_flag = net->statement()->emit_proc(this) && rc_flag;
assert(stmt_cur_);
View
1 t-dll-api.cc
@@ -21,6 +21,7 @@
# include "StringHeap.h"
# include "t-dll.h"
# include "discipline.h"
+# include "ivl_alloc.h"
# include <cstdlib>
# include <cstdio>
# include <cstring>
View
11 t-dll-expr.cc
@@ -19,6 +19,7 @@
# include "config.h"
+# include "ivl_alloc.h"
# include <iostream>
# include <cstring>
@@ -118,7 +119,6 @@ void dll_target::mul_expr_by_const_(long val)
ivl_expr_t dll_target::expr_from_value_(const verinum&val)
{
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr);
unsigned idx;
char*bits;
@@ -180,7 +180,6 @@ void dll_target::expr_binary(const NetEBinary*net)
ivl_expr_t rght = expr_;
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr_);
expr_->type_ = IVL_EX_BINARY;
expr_->value_= get_expr_type(net);
@@ -225,7 +224,6 @@ void dll_target::expr_const(const NetEConst*net)
assert(expr_ == 0);
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr_);
expr_->value_= net->expr_type();
FILE_NAME(expr_, net);
@@ -312,7 +310,6 @@ void dll_target::expr_event(const NetEEvent*net)
assert(expr_ == 0);
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr_);
expr_->type_ = IVL_EX_EVENT;
FILE_NAME(expr_, net);
@@ -337,7 +334,6 @@ void dll_target::expr_scope(const NetEScope*net)
assert(expr_ == 0);
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr_);
expr_->type_ = IVL_EX_SCOPE;
expr_->value_= IVL_VT_VOID;
@@ -358,7 +354,6 @@ void dll_target::expr_select(const NetESelect*net)
ivl_expr_t rght = expr_;
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr_);
FILE_NAME(expr_, net);
expr_->type_ = IVL_EX_SELECT;
@@ -376,7 +371,6 @@ void dll_target::expr_sfunc(const NetESFunc*net)
assert(expr_ == 0);
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr);
expr->type_ = IVL_EX_SFUNC;
FILE_NAME(expr, net);
@@ -407,7 +401,6 @@ void dll_target::expr_ternary(const NetETernary*net)
assert(expr_ == 0);
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr);
expr->type_ = IVL_EX_TERNARY;
FILE_NAME(expr, net);
@@ -449,7 +442,6 @@ void dll_target::expr_signal(const NetESignal*net)
}
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr_);
expr_->type_ = IVL_EX_SIGNAL;
expr_->value_= net->expr_type();
@@ -478,7 +470,6 @@ void dll_target::expr_ufunc(const NetEUFunc*net)
assert(expr_ == 0);
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
- assert(expr);
expr->type_ = IVL_EX_UFUNC;
FILE_NAME(expr, net);
View
4 t-dll-proc.cc
@@ -22,6 +22,7 @@
# include <iostream>
+# include "ivl_alloc.h"
# include <cstring>
# include "target.h"
# include "ivl_target.h"
@@ -59,7 +60,6 @@ bool dll_target::process(const NetProcTop*net)
assert(stmt_cur_ == 0);
stmt_cur_ = (struct ivl_statement_s*)calloc(1, sizeof*stmt_cur_);
- assert(stmt_cur_);
rc_flag = net->statement()->emit_proc(this) && rc_flag;
assert(stmt_cur_);
@@ -80,7 +80,6 @@ void dll_target::task_def(const NetScope*net)
assert(stmt_cur_ == 0);
stmt_cur_ = (struct ivl_statement_s*)calloc(1, sizeof*stmt_cur_);
- assert(stmt_cur_);
def->proc()->emit_proc(this);
assert(stmt_cur_);
@@ -96,7 +95,6 @@ bool dll_target::func_def(const NetScope*net)
assert(stmt_cur_ == 0);
stmt_cur_ = (struct ivl_statement_s*)calloc(1, sizeof*stmt_cur_);
- assert(stmt_cur_);
def->proc()->emit_proc(this);
assert(stmt_cur_);
View
9 t-dll.cc
@@ -21,6 +21,7 @@
# include <iostream>
+# include "ivl_alloc.h"
# include <cstring>
# include <cstdio> // sprintf()
# include "compiler.h"
@@ -561,9 +562,12 @@ void dll_target::add_root(ivl_design_s &des__, const NetScope *s)
des__.nroots_++;
if (des__.roots_)
- des__.roots_ = (ivl_scope_t *)realloc(des__.roots_, des__.nroots_ * sizeof(ivl_scope_t));
+ des__.roots_ = (ivl_scope_t *)realloc(des__.roots_,
+ des__.nroots_ *
+ sizeof(ivl_scope_t));
else
- des__.roots_ = (ivl_scope_t *)malloc(des__.nroots_ * sizeof(ivl_scope_t));
+ des__.roots_ = (ivl_scope_t *)malloc(des__.nroots_ *
+ sizeof(ivl_scope_t));
des__.roots_[des__.nroots_ - 1] = root_;
}
@@ -1256,7 +1260,6 @@ void dll_target::udp(const NetUDP*net)
u = new struct ivl_udp_s;
u->nrows = net->rows();
u->table = (ivl_udp_s::ccharp_t*)malloc((u->nrows+1)*sizeof(char*));
- assert(u->table);
u->table[u->nrows] = 0x0;
u->nin = net->nin();
u->sequ = net->is_sequential();
View
1 tgt-fpga/d-generic-edif.c
@@ -19,6 +19,7 @@
# include "device.h"
# include "fpga_priv.h"
+# include "ivl_alloc.h"
# include <stdlib.h>
# include <string.h>
# include <assert.h>
View
1 tgt-fpga/edif.c
@@ -18,6 +18,7 @@
*/
# include "edif.h"
+# include "ivl_alloc.h"
# include <stdlib.h>
# include <string.h>
# include <assert.h>
View
1 tgt-fpga/mangle.c
@@ -18,6 +18,7 @@
*/
# include "fpga_priv.h"
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
View
1 tgt-fpga/xilinx.c
@@ -21,6 +21,7 @@
# include "generic.h"
# include "xilinx.h"
# include "fpga_priv.h"
+# include "ivl_alloc.h"
# include <stdlib.h>
# include <string.h>
# include <assert.h>
View
1 tgt-pal/emit_jed.c
@@ -20,6 +20,7 @@
# include "config.h"
# include "priv.h"
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <assert.h>
View
30 tgt-pal/fit_log.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000 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
@@ -16,13 +16,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#ifdef HAVE_CVS_IDENT
-#ident "$Id: fit_log.c,v 1.6 2007/02/26 19:49:50 steve Exp $"
-#endif
# include "config.h"
# include "ivl_target.h"
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <assert.h>
@@ -125,27 +123,3 @@ int fit_logic(void)
return 0;
}
-
-/*
- * $Log: fit_log.c,v $
- * Revision 1.6 2007/02/26 19:49:50 steve
- * Spelling fixes (larry doolittle)
- *
- * Revision 1.5 2002/08/12 01:35:03 steve
- * conditional ident string using autoconfig.
- *
- * Revision 1.4 2001/07/25 03:10:50 steve
- * Create a config.h.in file to hold all the config
- * junk, and support gcc 3.0. (Stephan Boettcher)
- *
- * Revision 1.3 2001/05/16 03:55:30 steve
- * Update to new LPM API for flip-flops.
- *
- * Revision 1.2 2001/02/07 22:22:00 steve
- * ivl_target header search path fixes.
- *
- * Revision 1.1 2000/12/14 23:37:47 steve
- * Start support for fitting the logic.
- *
- */
-
View
2 tgt-pal/imain.c
@@ -25,6 +25,7 @@
# include "priv.h"
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <assert.h>
@@ -84,7 +85,6 @@ int target_design(ivl_design_t des)
/* Allocate the pin array, ready to start assigning resources. */
bind_pin = calloc(pins, sizeof (struct pal_bind_s));
- assert(bind_pin);
/* Connect all the macrocells that drive pins to the pin that
they drive. This doesn't yet look at the design, but is
View
1 tgt-stub/stub.c
@@ -28,6 +28,7 @@
# include "version_tag.h"
# include "config.h"
# include "priv.h"
+# include "ivl_alloc.h"
# include <stdlib.h>
# include <inttypes.h>
# include <string.h>
View
2 tgt-vvp/draw_net_input.c
@@ -18,6 +18,7 @@
*/
# include "vvp_priv.h"
+# include "ivl_alloc.h"
# include <stdlib.h>
# include <math.h>
# include <string.h>
@@ -640,7 +641,6 @@ static void draw_net_input_x(ivl_nexus_t nex,
if (ndrivers >= adrivers) {
adrivers += 4;
drivers = realloc(drivers, adrivers*sizeof(ivl_nexus_ptr_t));
- assert(drivers);
}
drivers[ndrivers] = nptr;
ndrivers += 1;
View
1 tgt-vvp/draw_vpi.c
@@ -18,6 +18,7 @@
*/
# include "vvp_priv.h"
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
# include <assert.h>
View
1 tgt-vvp/eval_expr.c
@@ -18,6 +18,7 @@
*/
# include "vvp_priv.h"
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
# include <assert.h>
View
1 tgt-vvp/modpath.c
@@ -18,6 +18,7 @@
*/
# include "vvp_priv.h"
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
# include <assert.h>
View
4 tgt-vvp/vvp_scope.c
@@ -18,6 +18,7 @@
*/
# include "vvp_priv.h"
+# include "ivl_alloc.h"
# include <stdlib.h>
# include <math.h>
# include <string.h>
@@ -59,7 +60,6 @@ const char *vvp_mangle_id(const char *id)
unsigned int nlen = strlen(id) + 4*(++nesc) + 1;
if (out_len < nlen) {
out = realloc(out, nlen);
- assert(out);
out_len = nlen;
}
if (n) {
@@ -109,7 +109,6 @@ const char *vvp_mangle_name(const char *id)
unsigned int nlen = strlen(id) + 2*(++nesc) + 1;
if (out_len < nlen) {
out = realloc(out, nlen);
- assert(out);
out_len = nlen;
}
if (n) {
@@ -738,7 +737,6 @@ static void draw_udp_in_scope(ivl_net_logic_t lptr)
if (i >= nudps) {
udps = realloc(udps, (nudps+1)*sizeof(ivl_udp_t));
- assert(udps);
udps[nudps++] = udp;
draw_udp_def(udp);
}
View
1 vpi/sdf_parse.y
@@ -24,6 +24,7 @@ static void yyerror(const char*msg);
# include "vpi_user.h"
# include "sdf_parse_priv.h"
# include "sdf_priv.h"
+# include "ivl_alloc.h"
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
View
1 vpi/stringheap.c
@@ -19,6 +19,7 @@
# include "sys_priv.h"
# include "stringheap.h"
+# include "ivl_alloc.h"
# include <string.h>
# include <stdlib.h>
# include <assert.h>
View
1 vpi/sys_display.c
@@ -18,6 +18,7 @@
*/
# include "sys_priv.h"
+# include "ivl_alloc.h"
# include <assert.h>
# include <string.h>
# include <errno.h>
View
1 vpi/sys_fileio.c
@@ -18,6 +18,7 @@
*/
# include "sys_priv.h"
+# include "ivl_alloc.h"
# include <assert.h>
# include <ctype.h>
# include <errno.h>
View
1 vpi/sys_fst.c
@@ -25,6 +25,7 @@
* This file contains the implementations of the FST related functions.
*/
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
View
1 vpi/sys_lxt.c
@@ -26,6 +26,7 @@
* This file contains the implementations of the LXT related functions.
*/
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
View
1 vpi/sys_lxt2.c
@@ -26,6 +26,7 @@
* This file contains the implementations of the LXT2 related functions.
*/
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
View
1 vpi/sys_priv.c
@@ -18,6 +18,7 @@
*/
#include "sys_priv.h"
+#include "ivl_alloc.h"
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
View
2 vpi/sys_random_mti.c
@@ -20,6 +20,7 @@
# include "sys_priv.h"
# include "sys_random.h"
+# include "ivl_alloc.h"
# include <assert.h>
# include <stdlib.h>
# include <math.h>
@@ -164,4 +165,3 @@ void sys_random_mti_register()
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
}
-
View
1 vpi/sys_readmem.c
@@ -18,6 +18,7 @@
*/
# include "sys_priv.h"
+# include "ivl_alloc.h"
# include <ctype.h>
# include <string.h>
# include <stdlib.h>
View
1 vpi/sys_scanf.c
@@ -22,6 +22,7 @@
# define _SVID_SOURCE 1
# include "sys_priv.h"
+# include "ivl_alloc.h"
# include <ctype.h>
# include <errno.h>
# include <string.h>
View
1 vpi/sys_vcd.c
@@ -24,6 +24,7 @@
* This file contains the implementations of the VCD related functions.
*/
+# include "ivl_alloc.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
View
13 vpi/v2005_math.c
@@ -20,6 +20,7 @@
*/
#include "vpi_config.h"
+#include "ivl_alloc.h"
#include <assert.h>
#include <math.h>
#include <stdlib.h>
@@ -175,12 +176,6 @@ static PLI_INT32 va_single_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
fun_data = malloc(sizeof(va_single_t));
- /* Check that malloc gave use some memory. */
- if (fun_data == 0) {
- va_error_message(callh, "%s failed to allocate memory.\n", name);
- return 0;
- }
-
/* Check that there are arguments. */
if (argv == 0) {
va_error_message(callh, "%s requires one argument.\n", name);
@@ -257,12 +252,6 @@ static PLI_INT32 va_double_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
fun_data = malloc(sizeof(va_double_t));
- /* Check that malloc gave use some memory. */
- if (fun_data == 0) {
- va_error_message(callh, "%s failed to allocate memory.\n", name);
- return 0;
- }
-
/* Check that there are arguments. */
if (argv == 0) {
va_error_message(callh, "%s requires two arguments.\n", name);
View
13 vpi/va_math.c
@@ -20,6 +20,7 @@
*/
#include "vpi_config.h"
+#include "ivl_alloc.h"
#include <assert.h>
#include <math.h>
#include <stdlib.h>
@@ -202,12 +203,6 @@ static PLI_INT32 va_single_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
fun_data = malloc(sizeof(va_single_t));
- /* Check that malloc gave use some memory. */
- if (fun_data == 0) {
- va_error_message(callh, "%s failed to allocate memory.\n", name);
- return 0;
- }
-
/* Check that there are arguments. */
if (argv == 0) {
va_error_message(callh, "%s requires one argument.\n", name);
@@ -284,12 +279,6 @@ static PLI_INT32 va_double_argument_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *ud)
fun_data = malloc(sizeof(va_double_t));
- /* Check that malloc gave use some memory. */
- if (fun_data == 0) {
- va_error_message(callh, "%s failed to allocate memory.\n", name);
- return 0;
- }
-
/* Check that there are arguments. */
if (argv == 0) {
va_error_message(callh, "%s requires two arguments.\n", name);
View
3 vpi/vcd_priv.c
@@ -19,6 +19,7 @@
#include "sys_priv.h"
#include "vcd_priv.h"
+#include "ivl_alloc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -56,7 +57,6 @@ void vcd_names_add(struct vcd_names_list_s*tab, const char *name)
{
struct vcd_names_s *nl = (struct vcd_names_s *)
malloc(sizeof(struct vcd_names_s));
- assert(nl);
nl->name = strdup_sh(&name_heap, name);
nl->next = tab->vcd_names_list;
tab->vcd_names_list = nl;
@@ -110,7 +110,6 @@ void vcd_names_sort(struct vcd_names_list_s*tab)
tab->vcd_names_sorted = (const char **)
realloc(tab->vcd_names_sorted,
tab->sorted_names*(sizeof(const char *)));
- assert(tab->vcd_names_sorted);
l = tab->vcd_names_sorted + tab->sorted_names - tab->listed_names;
tab->listed_names = 0;
View
1 vvp/array.cc
@@ -26,6 +26,7 @@
#ifdef CHECK_WITH_VALGRIND
#include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cstdlib>
# include <cstring>
# include <climits>
View
1 vvp/compile.cc
@@ -28,6 +28,7 @@
# include "vpi_priv.h"
# include "parse_misc.h"
# include "statistics.h"
+# include "ivl_alloc.h"
# include <iostream>
# include <list>
# include <cstdlib>
View
1 vvp/delay.cc
@@ -24,6 +24,7 @@
#ifdef CHECK_WITH_VALGRIND
#include "vvp_cleanup.h"
#endif
+#include "ivl_alloc.h"
#include <iostream>
#include <cstdlib>
#include <list>
View
2 vvp/lexor.lex
@@ -25,6 +25,7 @@
# include "parse_misc.h"
# include "compile.h"
# include "parse.h"
+# include "ivl_alloc.h"
# include <cstring>
# include <cassert>
@@ -73,7 +74,6 @@ static char* strdupnew(char const *str)
[1-9][0-9]*("'b"|"'sb")[01xz]+ {
yylval.vect.idx = strtoul(yytext, 0, 10);
yylval.vect.text = (char*)malloc(yylval.vect.idx + 2);
- assert(yylval.vect.text);
char*dest = yylval.vect.text;
const char*bits = strchr(yytext, '\'');
View
1 vvp/parse.y
@@ -22,6 +22,7 @@
# include "parse_misc.h"
# include "compile.h"
# include "delay.h"
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
# include <cassert>
View
1 vvp/parse_misc.cc
@@ -19,6 +19,7 @@
# include "parse_misc.h"
# include "compile.h"
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
View
1 vvp/stop.cc
@@ -28,6 +28,7 @@
# include "vpi_priv.h"
# include "vthread.h"
# include "schedule.h"
+# include "ivl_alloc.h"
# include <cstdio>
# include <cctype>
#ifdef USE_READLINE
View
1 vvp/udp.cc
@@ -27,6 +27,7 @@
#include "config.h"
#ifdef CHECK_WITH_VALGRIND
#include "vvp_cleanup.h"
+#include "ivl_alloc.h"
#endif
#include <cassert>
#include <cstdlib>
View
1 vvp/vpi_const.cc
@@ -23,6 +23,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
# include <cstring>
View
1 vvp/vpi_event.cc
@@ -19,6 +19,7 @@
# include "compile.h"
# include "vpi_priv.h"
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
# include <cstring>
View
1 vvp/vpi_iter.cc
@@ -22,6 +22,7 @@
*/
# include "vpi_priv.h"
+# include "ivl_alloc.h"
# include <cstdlib>
# include <cassert>
View
1 vvp/vpi_mcd.cc
@@ -22,6 +22,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cassert>
# include <cstdarg>
# include <cstdio>
View
3 vvp/vpi_modules.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2001-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
@@ -21,6 +21,7 @@
# include "vpi_priv.h"
# include "ivl_dlfcn.h"
# include "vvp_cleanup.h"
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstring>
# include <sys/types.h>
View
1 vvp/vpi_real.cc
@@ -24,6 +24,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
# include <cstring>
View
1 vvp/vpi_scope.cc
@@ -25,6 +25,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cstring>
# include <cstdlib>
# include <cassert>
View
1 vvp/vpi_signal.cc
@@ -31,6 +31,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cmath>
# include <iostream>
# include <cstdio>
View
1 vvp/vpi_tasks.cc
@@ -29,6 +29,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
# include <cstring>
View
1 vvp/vpi_vthr_vector.cc
@@ -30,6 +30,7 @@
# include "vvp_cleanup.h"
# include <map>
#endif
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstdlib>
# include <cassert>
View
5 vvp/vpip_to_dec.cc
@@ -23,6 +23,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <cstdio>
# include <cstring>
# include <climits> /* for CHAR_BIT */
@@ -149,9 +150,7 @@ unsigned vpip_vec4_to_dec_str(const vvp_vector4_t&vec4,
#define ALLOC_MARGIN 4
if (!valv || vlen > vlen_alloc) {
if (valv) free(valv);
- valv = (unsigned long*)
- calloc( vlen+ALLOC_MARGIN, sizeof (*valv));
- if (!valv) {perror("malloc"); return 0; }
+ valv = (unsigned long*) calloc(vlen+ALLOC_MARGIN, sizeof (*valv));
vlen_alloc=vlen+ALLOC_MARGIN;
} else {
memset(valv,0,vlen*sizeof(valv[0]));
View
1 vvp/vvp_island.cc
@@ -25,6 +25,7 @@
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
+# include "ivl_alloc.h"
# include <iostream>
# include <list>
# include <cassert>
View
3 vvp/vvp_net.cc
@@ -33,7 +33,8 @@
#ifdef CHECK_WITH_VALGRIND
# include <valgrind/memcheck.h>
# include <map>
-# include "sfunc.h"
+# include "sfunc.h"
+# include "ivl_alloc.h"
#endif
permaheap vvp_net_fun_t::heap_;
View
1 vvp/vvp_net.h
@@ -23,6 +23,7 @@
# include "vpi_user.h"
# include "vvp_vpi_callback.h"
# include "permaheap.h"
+# include "ivl_alloc.h"
# include <cstddef>
# include <cstdlib>
# include <cstring>

0 comments on commit cb86fb1

Please sign in to comment.
Something went wrong with that request. Please try again.