From 757fd0a37811ed5c5569ba3fdc89d4ea56ffcb2b Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 22 Mar 2023 11:22:41 +0100 Subject: [PATCH] better range checking for commands "xschem get schname" and "xschem get sch_path" --- doc/xschem_man/developer_info.html | 2 +- src/scheduler.c | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index b9efcb9d..a0b4ad56 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -632,7 +632,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
  • temp_dir get windows temporary dir
  • text_svg return 1 if using <text> elements in svg export
  • textlayer layer number for texts
  • -
  • top_path get top hier path of current window (always "") for tabbed if
  • +
  • top_path get top hier path of current window (always "" for tabbed if)
  • topwindow same as top_path but main window returned as "."
  • version return xschem version
  • wirelayer layer used for wires
  • diff --git a/src/scheduler.c b/src/scheduler.c index 446022a9..9d029a22 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -942,9 +942,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg /* allows to retrieve name of n-th parent schematic */ if(argc > 3) x = atoi(argv[3]); else x = xctx->currsch; - if(x<0 && xctx->currsch+x>=0) { - Tcl_SetResult(interp, xctx->sch[xctx->currsch+x], TCL_VOLATILE); - } else if(x<=xctx->currsch) { + if(x < 0 ) x = xctx->currsch + x; + if(x<=xctx->currsch && x >= 0) { Tcl_SetResult(interp, xctx->sch[x], TCL_VOLATILE); } } @@ -953,9 +952,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg int x; if(argc > 3) x = atoi(argv[3]); else x = xctx->currsch; - if(x<0 && xctx->currsch+x>=0) { - Tcl_SetResult(interp, xctx->sch_path[xctx->currsch+x], TCL_VOLATILE); - } else if(x<=xctx->currsch) { + if(x < 0 ) x = xctx->currsch + x; + if(x<=xctx->currsch && x >= 0) { Tcl_SetResult(interp, xctx->sch_path[x], TCL_VOLATILE); } } @@ -1009,7 +1007,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } /* top_path="" for main window, ".x1", ".x2", ... for additional windows. * always "" in tabbed interface */ - else if(!strcmp(argv[2], "top_path")) { /* get top hier path of current window (always "") for tabbed if */ + else if(!strcmp(argv[2], "top_path")) { /* get top hier path of current window (always "" for tabbed if) */ Tcl_SetResult(interp, xctx->top_path, TCL_VOLATILE); } /* same as above but main window returned as "." */