MaMu
MaMu

Reputation: 1869

Address 0x66 out of bounds

closeTs in struct tic gives me an error - tsP=0x66 <Address 0x66 out of bounds>. I try to fill it from oracle entry and if not, i try to assign a value. But I'm accessing it wrong in fillFields. Could someone give me a hint how can I fix it? I have cutted a lot off, but imho it is enough to be able to get the problem:

typedef struct tic {
    char  closeTs[19];
    float close;
}tic, *ticP;

int buildQotHash(GTree* tree, char (*str)[3000])
{
    tic *t = malloc(sizeof(tic))  ;
    while (OCI_FetchNext(rs))
    {
        if (OCI_GetDate(rs, 4) != NULL) OCI_DateToText(OCI_GetDate(rs, 4), 
            "DD.MM.YYYY HH24:MI", 19, t->closeTs );
    }
} 
void fillField(char* match, double* pf, char* tsP, char* message )
{

}
void fillFields(tic *t )
{
    fillField( CLOSEVORTAG, &t->close, t->closeTs,"CLOSEVORTAG,             " );
}

void processXML(char *start, char *stop, GTree* t)
{
    tic *ti  ; 
    if (triP != NULL && (key = g_tree_lookup (t, triP))!= NULL ) ti = (ticP)key;
    fillFields(ti);
}

Upvotes: 0

Views: 348

Answers (1)

rodrigo
rodrigo

Reputation: 98328

I feel that the code you posted is quite incomplete, so I'm mostly guessing here...

In your function processXML what happens if the condition is not met?

void processXML(char *start, char *stop, GTree* t)
{
    tic *ti ; 
    if (triP != NULL && (key = g_tree_lookup (t, triP))!= NULL )
        ti = (ticP)key;
    //or else???
    fillFields(ti);
}

What happens is that ti is left uninitialized, and so any use of it will result in Undefined behavior. You are lucky and you are getting an out of bounds error.

What you probably want is:

void processXML(char *start, char *stop, GTree* t)
{
    //where is key declared, BTW???
    if (triP != NULL && (key = g_tree_lookup (t, triP))!= NULL )
    {
        tic *ti = (ticP)key;
        fillFields(ti);
    }
    // or else do nothing
}

That's why I always recommend to declare variables nearest to their use. This way ti is never uninitialized, and so your original mistake is impossible.

Upvotes: 2

Related Questions