avoid allocating 0 byte objects in hash_iterator.c, some fixes in xschem subcommands ("clear", "get lastsel", "align", "wire")

This commit is contained in:
Stefan Frederik 2021-12-08 02:38:56 +01:00
parent fa25edabec
commit e45e3caa84
2 changed files with 29 additions and 25 deletions

View File

@ -26,21 +26,24 @@ void init_inst_iterator(struct iterator_ctx *ctx, double x1, double y1, double x
{
ctx->instflag = NULL;
dbg(3, "init_inst_iterator(): instances=%d\n", xctx->instances);
my_realloc(135, &ctx->instflag, xctx->instances*sizeof(unsigned short));
memset(ctx->instflag, 0, xctx->instances*sizeof(unsigned short));
if(xctx->instances) {
my_realloc(135, &ctx->instflag, xctx->instances*sizeof(unsigned short));
memset(ctx->instflag, 0, xctx->instances*sizeof(unsigned short));
}
/* calculate square 4 1st corner of drawing area */
ctx->x1a = floor(x1/BOXSIZE) ;
ctx->y1a = floor(y1/BOXSIZE) ;
ctx->x1a = floor(x1 / BOXSIZE) ;
ctx->y1a = floor(y1 / BOXSIZE) ;
/* calculate square 4 2nd corner of drawing area */
ctx->x2a = floor(x2/BOXSIZE);
ctx->y2a = floor(y2/BOXSIZE);
ctx->x2a = floor(x2 / BOXSIZE);
ctx->y2a = floor(y2 / BOXSIZE);
ctx->i = ctx->x1a;
ctx->j = ctx->y1a;
ctx->tmpi = ctx->i % NBOXES; if(ctx->tmpi<0) ctx->tmpi+=NBOXES;
ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj<0) ctx->tmpj+=NBOXES;
ctx->counti=0;
ctx->instanceptr=xctx->inst_spatial_table[ctx->tmpi][ctx->tmpj];
ctx->countj=0;
ctx->tmpi = ctx->i % NBOXES; if(ctx->tmpi < 0) ctx->tmpi += NBOXES;
ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES;
ctx->counti = 0;
ctx->instanceptr = xctx->inst_spatial_table[ctx->tmpi][ctx->tmpj];
ctx->countj = 0;
}
@ -79,8 +82,10 @@ void init_wire_iterator(struct iterator_ctx *ctx, double x1, double y1, double x
{
ctx->wireflag = NULL;
dbg(3, "init_wire_iterator(): wires=%d\n", xctx->wires);
my_realloc(136, &ctx->wireflag, xctx->wires*sizeof(unsigned short));
memset(ctx->wireflag, 0, xctx->wires*sizeof(unsigned short));
if(xctx->wires) {
my_realloc(136, &ctx->wireflag, xctx->wires*sizeof(unsigned short));
memset(ctx->wireflag, 0, xctx->wires*sizeof(unsigned short));
}
/* calculate square 4 1st corner of drawing area */
ctx->x1a = floor(x1 / BOXSIZE) ;
ctx->y1a = floor(y1 / BOXSIZE) ;
@ -89,9 +94,9 @@ void init_wire_iterator(struct iterator_ctx *ctx, double x1, double y1, double x
ctx->y2a = floor(y2 / BOXSIZE);
ctx->i = ctx->x1a;
ctx->j = ctx->y1a;
ctx->tmpi=ctx->i % NBOXES; if(ctx->tmpi < 0) ctx->tmpi += NBOXES;
ctx->tmpj=ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES;
ctx->counti=0;
ctx->tmpi = ctx->i % NBOXES; if(ctx->tmpi < 0) ctx->tmpi += NBOXES;
ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES;
ctx->counti = 0;
ctx->wireptr = xctx->wire_spatial_table[ctx->tmpi][ctx->tmpj];
ctx->countj = 0;
}

View File

@ -304,7 +304,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
cmd_found = 1;
xctx->push_undo();
round_schematic_to_grid(tclgetdoublevar("cadsnap"));
if(tclgetvar("autotrim_wires")) trim_wires();
if(tclgetboolvar("autotrim_wires")) trim_wires();
set_modify(1);
xctx->prep_hash_inst=0;
xctx->prep_hash_wires=0;
@ -412,11 +412,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else if(!strcmp(argv[1],"clear"))
{
int cancel;
int cancel = 0;
cmd_found = 1;
cancel=save(1);
if(cancel != -1){ /* -1 means user cancel save request */
if( argc < 3 || strcmp(argv[2], "force") ) cancel=save(1);
if(cancel != -1) { /* -1 means user cancel save request */
char name[PATH_MAX];
struct stat buf;
int i;
@ -784,11 +784,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_SetResult(interp, s,TCL_VOLATILE);
}
else if(!strcmp(argv[2],"lastsel")) {
char s[30];
rebuild_selected_array();
if( xctx->lastsel != 0 )
Tcl_SetResult(interp, "1",TCL_STATIC);
else
Tcl_SetResult(interp, "0",TCL_STATIC);
my_snprintf(s, S(s), "%d", xctx->lastsel);
Tcl_SetResult(interp, s,TCL_VOLATILE);
}
else if(!strcmp(argv[2],"line_width")) {
char s[40];
@ -2644,7 +2643,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
save = xctx->draw_window; xctx->draw_window = 1;
drawline(WIRELAYER,NOW, x1,y1,x2,y2, 0);
xctx->draw_window = save;
if(tclgetvar("autotrim_wires")) trim_wires();
if(tclgetboolvar("autotrim_wires")) trim_wires();
}
else xctx->ui_state |= MENUSTARTWIRE;
}