diff --git a/vpi/sys_fileio.c b/vpi/sys_fileio.c index 305775390..667d78fef 100644 --- a/vpi/sys_fileio.c +++ b/vpi/sys_fileio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2012 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 @@ -680,7 +680,8 @@ static PLI_INT32 sys_fread_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) vpi_free_object(argv); } - words = (width+31)/32; + assert(width > 0); + words = (width - 1)/32 + 1; vector = calloc(words, sizeof(s_vpi_vecval)); bpe = (width+7)/8; diff --git a/vvp/vpi_const.cc b/vvp/vpi_const.cc index 2b95fe644..f7ca58757 100644 --- a/vvp/vpi_const.cc +++ b/vvp/vpi_const.cc @@ -121,7 +121,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp) { unsigned uint_value; p_vpi_vecval vecp; - int size = strlen(value_); + unsigned size = strlen(value_); char*rbuf = 0; char*cp; @@ -145,7 +145,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp) } rbuf = need_result_buf(size + 1, RBUF_VAL); uint_value = 0; - for(int i=0; i=0; bit--){ + for(unsigned i=0; i=0; bit -= 1){ *cp++ = "01"[ (value_[i]>>bit)&1 ]; } } @@ -168,8 +168,8 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp) case vpiHexStrVal: rbuf = need_result_buf(2 * size + 1, RBUF_VAL); cp = rbuf; - for(int i=0; i=0; nibble--){ + for(unsigned i=0; i=0; nibble -= 1){ *cp++ = "0123456789abcdef"[ (value_[i]>>(nibble*4))&15 ]; } } @@ -184,8 +184,8 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp) case vpiIntVal: vp->value.integer = 0; - for(int i=0; i=0; bit--){ + for(unsigned i=0; i=0; bit -= 1){ vp->value.integer <<= 1; vp->value.integer += (value_[i]>>bit)&1; } @@ -200,7 +200,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp) uint_value = 0; vecp = vp->value.vector; vecp->aval = vecp->bval = 0; - for(int i=0; iaval |= value_[i] << uint_value*8; uint_value += 1; if (uint_value > 3) { diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index dd821c6c4..3478fed40 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -467,7 +467,7 @@ static void format_vpiVectorVal(vvp_signal_value*sig, int base, unsigned wid, { long end = base + (signed)wid; unsigned int obit = 0; - unsigned hwid = (wid - 1)/32 + 1; + unsigned hwid = (wid + 31)/32; s_vpi_vecval *op = (p_vpi_vecval) need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);