Privacy and Security Notice

Archived Messages for CDEV_1997@cebaf.gov: RE: get problem

RE: get problem

heyes@CEBAF.GOV
Tue, 25 Mar 1997 13:00:25 -0500 (EST)

I had this probelm a while back with tclcdev, there is a temporary string used
to hold return values from get which is only 255 charactrs long. The fix ix to
modify the tclcdev code so that cdev malloc's the string rather than you pass
an existing string to it...

static char *cs;

// Format a cdevData into a tcl result
int Cdev_Handleresult(cdevData & result, Tcl_DString & ds) {
int i,j,k,tag,len;
size_t dim;
char **sp;

// assume we always return the "value" tag
// Have to provide a way to retrieve other tags, like timestamp
result.tagC2I("value", &tag);
result.getDim(tag, &dim);

// Always retrieve the result as a char*, cdevData does the conversion for me!
Tcl_DStringInit(&ds);
if (dim == 0) {
result.get(tag,&cs);
if (cs)
Tcl_DStringAppend(&ds,cs,-1);
return TCL_OK;
}

Then again you seem to have a different (newer) tclcde than I have since I
don't have a TclCdevCollection::getResult. I told Chip about this bug a while
back...

On 25-Mar-97 Johannes van Zeijts wrote:
>I have found a serious problem with get, when I pass it a char*
>
>Consider the code below, I am asking for 255 chars of data (I allocated
>256). SYMPTOM: In the first iteration through the loop, the value of i
>is overwritten and ends up being some large integer.
>
>Changing the order of declaration to:
> int i;
> char res[256];
>
>fixes the problem. Looks like cdev is putting more in than I want.
>
> -Johannes
>
>
>void TclCdevCollection::getResult(Tcl_Interp *interp) {
> char res[256];
> int i;
> for (i = 0; i < ndevices; i++) {
> results[i].get(VALUE_TAG, res, 255);
> cout << i << endl;
>// Tcl_AppendElement(interp, res);
> }
>}

Graham

-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-
Beware of geeks bearing gifs... ;^) Tel:(757) 269-7030,http://alcor.jlab.org