RE: [ROOT] crash in cint api G__what_type

From: Philippe Canal (pcanal@fnal.gov)
Date: Tue Aug 10 2004 - 00:50:13 MEST


Hi Martin,

There is a missing protectin G__what_type.
However you should use
	ptr = (void*) G__what_type(name,mytype,0,0);

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Martin Goettlich
Sent: Monday, August 09, 2004 10:03 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] crash in cint api G__what_type


Hi there,

I'm using ROOT version 3.10/03 and I run into a segmentation violation 
when using Cint API G__what_type. This is the code of my executable:

#include <stdio.h>
#include <iostream>
#include <Api.h>

using namespace std;

int main() {

  int state;
  state=G__init_cint("Cint");
  switch(state) {
  case G__INIT_CINT_SUCCESS_MAIN:
    break;
  case G__INIT_CINT_SUCCESS:
    state=G__loadfile("rtscript.C");
    if(state==G__LOADFILE_SUCCESS) {


      cout<<"I want to test the type of a variable defined in 
'rtscript.C'."<<endl;
      void *ptr;
      char name[]="var";
      char mytype[200];
      char mytagname[200];
      char mytypename[200];
      ptr = (void*) G__what_type(name,mytype,mytagname,mytypename);
      if(strncmp("double",mytype,6)==0) {
        double* var = (double*) ptr;
        cout<<"Variable 'var' is a 'double' so the cast is save! Its 
value is: "<<*var<<endl;
      } else {
        cout<<"Variable 'var' is not a double."<<endl;
      }


    }
    break;
  case G__INIT_CINT_FAILURE:
  default:
    printf("Initialization of Cint failed.\n");
  }
  G__scratch_all();

}


rtscript.C looks like this (just one line):

double var = 47.11;

The executable crashes in the function G__what_type. I found out that it 
crashes in the line

 if(tagname) strcpy(tagname,G__struct.name[buf.tagnum]);

in cint/src/auxu.C where this funtion is defined because 
G__struct.name[buf.tagnum] is a null pointer.

When I comment out the lines

  if(tagname) strcpy(tagname,G__struct.name[buf.tagnum]);
  if(typename) strcpy(typename,G__newtype.name[buf.typenum]);

everything works. The output looks like this:

I want to test the type of a variable defined in rtscript.C.
Type of variable var: double
Variable 'var' is a double so the cast is save! Its value is: 47.11

So it works.

Did I make a mistake (perhaps I misunderstood something) or is it a root 
bug?


Cheers,

Martin



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET