Operating System - Linux
1753325 Members
4727 Online
108792 Solutions
New Discussion юеВ

local variables values disapearing after calling a function that uses libxml2

 
SOLVED
Go to solution
Pedro Dinis
Advisor

local variables values disapearing after calling a function that uses libxml2



what is happening is that i am creating some local variables char * user_txt, and when i call the function streamFileXML(CONFIG_FILE_NAME,ORACLE_BD_TAG,xmlelementos_oracle_bd);
for the first time it returns the values from the xml and fills the variables with the find tag function.

the problem occurs when i call streamFileXML(CONFIG_FILE_NAME,LIMITES_TAG,xmlelementos_limites); a second time but this time i am reading another tag from the xml, it returns the right values, but the value of the local variables char *usr_text;
char *passwd_text;
char *osid_text;
is gone, as you will see in the piece of the log file that i posted below:

before calling the xml reader for the second time :
dados a repetidos: (bdsn), (bdsn), (oesis)

after calling the xml reader function for the second time, these values (bdsn), (bdsn), (oesis) are missing

dados finales: (), (), (), (50)

thanks

elementoestrutura xmlelementos_oracle_bd[BIG_ENOUGH];
elementoestrutura xmlelementos_limites[BIG_ENOUGH];

char *usr_text;
char *passwd_text;
char *osid_text;
char *num_advertencias;

//ler o ficheiro de configuracao e sacar usr,passwd,osid


text_count=0;
LIBXML_TEST_VERSION

streamFileXML(CONFIG_FILE_NAME,ORACLE_BD_TAG,xmlelementos_oracle_bd);

xmlCleanupParser();
xmlMemoryDump();


usr_text=findtag("user",xmlelementos_oracle_bd);
passwd_text=findtag("passwd",xmlelementos_oracle_bd);
osid_text=findtag("osid",xmlelementos_oracle_bd);


sprintf( sstring, "dados a sem ser rep: (%s), (%s), (%s)", usr_text, passwd_text,osid_text);

log_message(LOG_FILE,sstring);
usr_text=findtag("user",xmlelementos_oracle_bd);
passwd_text=findtag("passwd",xmlelementos_oracle_bd);
osid_text=findtag("osid",xmlelementos_oracle_bd);

sprintf( sstring, "dados a repetidos: (%s), (%s), (%s)", usr_text, passwd_text,osid_text);
log_message(LOG_FILE,sstring);

text_count=0;

LIBXML_TEST_VERSION

streamFileXML(CONFIG_FILE_NAME,LIMITES_TAG,xmlelementos_limites);

xmlCleanupParser();
xmlMemoryDump();

num_advertencias=findtag("num_advertencias",xmlelementos_limites);

sprintf( sstring, "dados finales: (%s), (%s), (%s), (%s)",usr_text, passwd_text,osid_text ,num_advertencias);
log_message(LOG_FILE,sstring);





this is the log file created during the execution

[]-pedro:/home/pedro/bin>cat daemon.log
iniciar o daemonize
sprintf : demonio iniciado: Tue Jul 10 12:16:10 2007

lock file
drop user
fork off
fork off
exit parent
executando como filhos
umask
SETSID
CHDIR
el salir daemonize la funci├│n
crear la llave
iniciar el sem├бforo
estoy leyendo el conf.xml por primera vez
Text Count----->0
Text Count----->1
Text Count----->2
Oracle_name----->oracle_bd
entrei aqui
dados elemento==tag : (user)==(user) <<---->> (bdsn)
entrei aqui
dados elemento==tag : (passwd)==(user) <<---->> (bdsn)
dados elemento==tag : (passwd)==(passwd) <<---->> (bdsn)
entrei aqui
dados elemento==tag : (osid)==(user) <<---->> (bdsn)
dados elemento==tag : (osid)==(passwd) <<---->> (bdsn)
dados elemento==tag : (osid)==(osid) <<---->> (oesis)
dados a sem ser rep: (bdsn), (bdsn), (oesis)
entrei aqui
dados elemento==tag : (user)==(user) <<---->> (bdsn)
entrei aqui
dados elemento==tag : (passwd)==(user) <<---->> (bdsn)
dados elemento==tag : (passwd)==(passwd) <<---->> (bdsn)
entrei aqui
dados elemento==tag : (osid)==(user) <<---->> (bdsn)
dados elemento==tag : (osid)==(passwd) <<---->> (bdsn)
dados elemento==tag : (osid)==(osid) <<---->> (oesis)
dados a repetidos: (bdsn), (bdsn), (oesis)
Text Count----->0
Oracle_name----->limites
entrei aqui
dados elemento==tag : (num_advertencias)==(num_advertencias) <<---->> (50)
dados finales: (
), (), (), (50)
vou ficar a escrever na memoria ate que doa a barriga
[]-pedro:/home/pedro/bin>


this is the find tag function that goes to the array that was filled by the xml reader function

char * findtag(char * tag,elementoestrutura xmlelementos[])
{
char sstring[200];
char * texto;
int i =0;

log_message(LOG_FILE,"entrei aqui");
while(i< BIG_ENOUGH)
{

sprintf(sstring, "dados elemento==tag : (%s)==(%s) <<---->> (%s)", tag, xmlelementos[i].elemento,xmlelementos[i].texto);
log_message(LOG_FILE,sstring);
if(strcmp(tag,xmlelementos[i].elemento)==0)
{
texto=xmlelementos[i].texto;
return texto;
}

i++;
}
return "erro no XML";
}


SLB SLB SLB Glorioso
3 REPLIES 3
Steven E. Protter
Exalted Contributor
Solution

Re: local variables values disapearing after calling a function that uses libxml2

Shalom,

I can't debug your code.

If variables are being stepped on, check the specifications on the library and make sure you are not using names reserved by the library.

sEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: local variables values disapearing after calling a function that uses libxml2

What OS version are you on?
If you are on IPF, you can use a real compiler that has +check=bounds +check=stack to catch this type of corruption.

>SEP: If variables are being stepped on,

You can also set a hardware watch point to see who overwrites these variables.
Dennis Handly
Acclaimed Contributor

Re: local variables values disapearing after calling a function that uses libxml2

Is sstring big enough?
char sstring[200];
sprintf(sstring, "dados elemento==tag : (%s)==(%s) <<---->> (%s)", tag,

You may want to use snprintf, where you pass the size of sstring to prevent it from going out of bounds.