fix unfreed pointer in get_logic_value()

This commit is contained in:
Stefan Frederik 2020-12-28 12:29:57 +01:00
parent 47ed76374e
commit 4687133b5f
6 changed files with 30 additions and 31 deletions

View File

@ -214,7 +214,7 @@ static char *expandlabel_strbus_nobracket(char *s, int *n)
{
tmplen = sprintf(tmp, "%s%d,", s, n[i]);
/* strcpy(res+l,tmp); */
memcpy(res+l,tmp, tmplen+1); /* 20180923 */
memcpy(res+l,tmp, tmplen+1);
l+=tmplen;
}
my_free(736, &tmp);
@ -258,8 +258,8 @@ int *idx; /* for bus index & bus index ranges */
line: /* empty */
| list {
my_strdup(129, &(dest_string.str),$1.str); /*19102004 */
my_free(737, &$1.str); /*19102004 */
my_strdup(129, &(dest_string.str),$1.str);
my_free(737, &$1.str);
dest_string.m=$1.m;
}
;
@ -271,7 +271,7 @@ list: B_NAME {
}
| B_LINE {
dbg(3, "yyparse(): B_LINE\n");
$$.str = expandlabel_strdup($1); /* 19102004 prima era =$1 */
$$.str = expandlabel_strdup($1); /* prima era =$1 */
my_free(739, &$1);
$$.m = 1;
}
@ -344,7 +344,7 @@ list: B_NAME {
my_free(748, &$1);
dbg(3, "yyparse(): done making bus: n=%d\n",$3[0]);
$$.m=$3[0];
my_free(749, &$3); /*19102004 */
my_free(749, &$3);
idxsize=INITIALIDXSIZE;
}
| B_NAME '[' index_nobracket ']'
@ -354,13 +354,13 @@ list: B_NAME {
my_free(750, &$1);
dbg(3, "yyparse(): done making nobracket bus: n=%d\n",$3[0]);
$$.m=$3[0];
my_free(751, &$3); /*19102004 */
my_free(751, &$3);
idxsize=INITIALIDXSIZE;
}
;
index: B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
{
int i; /* 20120229 */
int i;
int sign;
sign = SIGN($3-$1);
@ -374,7 +374,7 @@ index: B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
if(sign==1 && i>=$3) break;
if(sign==-1 && i<=$3) break;
} /* /20120229 */
}
}
| B_IDXNUM ':' B_IDXNUM
{
@ -398,7 +398,7 @@ index: B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
}
| index ',' B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
{
int i; /* 20120229 */
int i;
int sign;
sign = SIGN($5-$3);
@ -409,7 +409,7 @@ index: B_IDXNUM ':' B_IDXNUM ':' B_IDXNUM
$$[$$[0]]=i;
if(sign==1 && i>=$5) break;
if(sign==-1 && i<=$5) break;
} /* /20120229 */
}
}
| index ',' B_IDXNUM ':' B_IDXNUM
{

View File

@ -867,13 +867,16 @@ int get_logic_value(int inst, int n)
/* fast option: dont use net_name() (no expandlabel though) */
/* THIS MUST BE DONE TO HANDLE VECTOR INSTANCES/BUSES */
/* my_strdup(1219, &netname, net_name(inst, n, &mult, 1, 0)); */
/* my_strdup(xxxx, &netname, net_name(inst, n, &mult, 1, 0)); */
my_strdup(1219, &netname, xctx->inst[inst].node[n]);
entry=bus_hilight_lookup(netname, 0, XLOOKUP);
if(!entry) return 2; /* LOGIC_X */
if(!entry) {
val = 2; /* LOGIC_X */
} else {
val = entry->value;
val = (val == LOGIC_0) ? 0 : (val == LOGIC_1) ? 1 : 2;
dbg(1, "get_logic_value(): inst=%d pin=%d net=%s val=%d\n", inst, n, netname, val);
/* dbg(1, "get_logic_value(): inst=%d pin=%d net=%s val=%d\n", inst, n, netname, val); */
}
my_free(1221, &netname);
return val;
}
@ -1007,8 +1010,8 @@ void propagate_logic()
if(!propag[0]) break;
propagate = atoi(propag);
if(propagate < 0 || propagate >= npin) {
dbg(0, "Error: inst: %s, pin %d, propagate_to set to %s <<%d>>\n",
xctx->inst[i].instname, j, propagate_str, propagate);
/* dbg(0, "Error: inst: %s, pin %d, propagate_to set to %s <<%d>>\n",
* xctx->inst[i].instname, j, propagate_str, propagate); */
continue;
}
if(!xctx->inst[i].node[propagate]) {
@ -1018,11 +1021,11 @@ void propagate_logic()
/* get net to propagate hilight to...*/
/* fast option: dont use net_name() (no expandlabel though) */
/* THIS MUST BE DONE TO HANDLE VECTOR INSTANCES/BUSES */
/* my_strdup(1220, &propagated_net, net_name(i, propagate, &mult, 1, 0)); */
/* my_strdup(xxx, &propagated_net, net_name(i, propagate, &mult, 1, 0)); */
my_strdup(1220, &propagated_net, xctx->inst[i].node[propagate]);
dbg(1, "propagate_logic(): inst %d pin %d propag=%s n=%d\n", i, j, propag, n);
dbg(1, "propagate_logic(): inst %d pin %d propagate=%d\n", i, j, propagate);
dbg(1, "propagate_logic(): propagated_net=%s\n", propagated_net);
/* dbg(1, "propagate_logic(): inst %d pin %d propag=%s n=%d\n", i, j, propag, n);
* dbg(1, "propagate_logic(): inst %d pin %d propagate=%d\n", i, j, propagate);
* dbg(1, "propagate_logic(): propagated_net=%s\n", propagated_net); */
/* add net to highlight list */
entry = bus_hilight_lookup(propagated_net, 0, XLOOKUP); /* destination pin */
oldval = (!entry) ? LOGIC_X : entry->value;

View File

@ -303,10 +303,6 @@ void hash_wire(int what, int n, int incremental)
struct wireentry *wptr;
xWire * const wire = xctx->wire;
/* >>>>> THIS IS NOT NEEDED !! delete_netlist_structs() does this... Why this HERE ?? <<<<< */
/* my_free(827, &wire[n].node); */
wire[n].end1 = wire[n].end2=-1;
x1=wire[n].x1;
x2=wire[n].x2;

View File

@ -1865,7 +1865,7 @@ void print_tedax_element(FILE *fd, int inst)
if(!numslots) my_strdup(494, &numslots, "1");
my_strdup(495, &name,xctx->inst[inst].instname);
/* my_strdup(496, &name,get_tok_value(xctx->inst[inst].prop_ptr,"name",0)); */
/* my_strdup(xxx, &name,get_tok_value(xctx->inst[inst].prop_ptr,"name",0)); */
if(!name) my_strdup(2, &name, get_tok_value(template, "name", 0));
/* allow format string override in instance */

View File

@ -66,7 +66,7 @@ END{
stale++
leak+= address[i]
print " address[ " i ", " idx[i] " ]= " address[i]
pipe = "grep -n 'my_.*(" idx[i] ",' *.c xschem.h"
pipe = "grep -n ' \([^/][^*]\) *my_.*(" idx[i] ",' *.c xschem.h"
while( pipe | getline a) print " " a
close(pipe)
}

View File

@ -134,12 +134,12 @@ void global_vhdl_netlist(int global) /* netlister driver */
/* for(i=0;i<xctx->instances;i++) */
/* { */
/* if(xctx->inst[i].ptr<0) continue; */
/* my_strdup(573, &type,(xctx->inst[i].ptr+ xctx->sym)->type); */
/* my_strdup(574, &sig_type,get_tok_value(xctx->inst[i].prop_ptr,"generic_type",0)); */
/* if(!sig_type || sig_type[0]=='\0') my_strdup(575, &sig_type,"std_logic"); */
/* my_strdup(xxx, &type,(xctx->inst[i].ptr+ xctx->sym)->type); */
/* my_strdup(xxx, &sig_type,get_tok_value(xctx->inst[i].prop_ptr,"generic_type",0)); */
/* if(!sig_type || sig_type[0]=='\0') my_strdup(xxx, &sig_type,"std_logic"); */
/* if( type && (strcmp(type,"generic"))==0) */
/* { */
/* my_strdup(576, &port_value,get_tok_value(xctx->inst[i].prop_ptr,"value", 0)); */
/* my_strdup(xxx, &port_value,get_tok_value(xctx->inst[i].prop_ptr,"value", 0)); */
/* str_tmp = xctx->inst[i].lab ? xctx->inst[i].lab : ""; */
/* if(!tmp) fprintf(fd,"generic (\n"); */
/* if(tmp) fprintf(fd," ;\n"); */