Thread View: comp.sys.sgi.graphics
2 messages
2 total messages
Started by LANGER STEVEN C
Wed, 13 Jan 1993 04:09
motif text widgets
Author: LANGER STEVEN C
Date: Wed, 13 Jan 1993 04:09
Date: Wed, 13 Jan 1993 04:09
66 lines
2478 bytes
2478 bytes
Hi folks;
Another question, this time on text widgets. I have a dialog with
several one line text widgets attached to it. To the right of each
text widget is a button. When the button is pressed, I want new text to show
up in the assocaited text widget.
________________________________________________
|
| text1 b1
|
| text2 b2
|
|
the code fragment is
{
dialog = XmCreateDialogShell (toplevel, ...
form = XmCreateForm (dialog, ...
text1 = XmCreateTextWidget (form, attach upper left
b1 = XmCreatePushButton (form, attach to right of text widget
XtAddCallback (b1, XmNactivateCallback, cbfunc, "b1");
XtManageChild (form);
XtManageChild (dialog);
}
void cbfunc (Widget w, XtPointer data, XtPointer dummy)
{
char *text;
char str[]="here i am";
if (strcasecmp(data, "b1") == 0)
{
temp = XtMalloc (sizeof(str));
temp[sizeof(str)] = 0 ; /* null terminator */
XmTextSetString (w, text);
XtFree (text);
}
}
This is my adaptation of Heller's example 15-2 file browser.c
program. The cbfunc is based on read_file.
The dialog is created and the default text is drawn, but when the b1
is pressed, I get a core dump and dbx zeros in on the
XmTextSetString call.
Any ideas on how to beat this?
--thanks in advance, steve
--
Steve Langer sglanger@argo.acs.oakland.edu (VMS)
Oakland University sglanger@vela.acs.oakland.edu (Ultrix)
---------------------------------------------------------------------------
Standard disclaimers apply. In addition, the author makes no guarantees,
concerning the grammatical accuracy of his writing. Therefore, any ^B's, ^C's,
midword character additions/deletions and other non-sense which occurs (after
the work leaves the author's decade old text editor via his decade old Amiga,
struggles through a local 1200 baud Merit server to be further mauled via the
remote VAX mail servers) is someone elses problem - namely yours.
---------------------------------------------------------------------------
Re: motif text widgets
Author: Mike Yang
Date: Wed, 13 Jan 1993 04:33
Date: Wed, 13 Jan 1993 04:33
32 lines
1295 bytes
1295 bytes
In article <1993Jan13.040941.4854@vela.acs.oakland.edu> sglanger@vela.acs.oakland.edu (LANGER STEVEN C) writes:
>void cbfunc (Widget w, XtPointer data, XtPointer dummy)
>{
> char *text;
> char str[]="here i am";
>
> if (strcasecmp(data, "b1") == 0)
> {
> temp = XtMalloc (sizeof(str));
> temp[sizeof(str)] = 0 ; /* null terminator */
> XmTextSetString (w, text);
> XtFree (text);
> }
>
>}
The variable text is uninitialized. Did you want to say:
XmTextSetString (w, temp);
instead?
Also, your null terminator is past the bounds of the array you allocate.
You probably want:
temp[sizeof(str)-1] = '\0';
instead.
-----------------------------------------------------------------------
Mike Yang Silicon Graphics, Inc.
mikey@sgi.com 415/390-1786
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads