Re: Tkined 1.4.1 odd code/bug

Juergen Schoenwaelder (schoenw@cs.utwente.nl)
Wed, 31 Jul 1996 16:07:36 +0200

Jim Madden <jmadden@ucsd.edu> wrote:

> The bit of code at scotty-2.1.1/tkined/generic/tkiFlash.c, line 111 that
> looks like

[...]

> can cause a segmentation fault because object itself may be NULL. I've
> made this happen consistently by deleting a flashing strip chart. I'm not
> sure what the intent is in having this reference to object outside the loop
> where "object" is set, so I can't propose a solution other than checking
> that object is not null.

Yes, this is broken. A couple of possible solutions. Below is patch
for tkiFlash.c that simply moves the code inside of the loop. This is
however much more expensive than necessary. Anyway, better to spend
some additional cycles than dumping core.

Juergen

*** tkiFlash.c-orig Tue Jul 16 19:31:02 1996
--- tkiFlash.c Wed Jul 31 16:02:56 1996
***************
*** 41,50 ****
FlashItem *p;
int max = 0;

- #if 1
Tk_Window window;
Tk_Window tkwin = Tk_MainWindow(interp);
- #endif

for (p = flashList; p != NULL; p = p->nextPtr) {

--- 41,48 ----
***************
*** 53,64 ****
object = Tki_LookupObject (p->id);
if (object == NULL) continue;

- #if 1
window = Tk_NameToWindow(interp, object->editor->toplevel, tkwin);
if (! window) {
continue;
}
- #endif

if (! object->editor->color) {
if ((object->flash) % 2) {
--- 51,60 ----
***************
*** 83,88 ****
--- 79,94 ----
"::color ", object->id, " ", color,
(char *) NULL);

+ #if 1
+ if (object->editor) {
+ char *buf = (object->flash % 2) ? "noicon" : "icon";
+ Tcl_VarEval(interp, "if ![winfo ismapped ",
+ object->editor->toplevel,
+ "] {", "wm iconbitmap ", object->editor->toplevel, " ",
+ buf, "}", (char *) NULL);
+ }
+ #endif
+
object->flash -= 1;

if (object->flash == 0) {
***************
*** 106,120 ****

flashList = NULL;
}
-
- #if 1
- if (object->editor) {
- char *buf = (object->flash % 2) ? "noicon" : "icon";
- Tcl_VarEval(interp, "if ![winfo ismapped ", object->editor->toplevel,
- "] {", "wm iconbitmap ", object->editor->toplevel, " ",
- buf, "}", (char *) NULL);
- }
- #endif

Tcl_Eval (interp, "update");

--- 112,117 ----