mercredi 1 mai 2019

Implicit construction returns an out of scope stack memory with a sanitizer - Why is that?

I currently have something like this code shown below my address sanitizer is complaining about out of stack memory at the statement

 const float *test = barInstance->play();

Now this is the code

class foo
{
public:
    foo()
    { }

    foo(const float* v)
    {
        varA = v[0];
    }
    ....
    ....
}

class Bar
{
    float _trans[3];
    foo Bar::play() const
    {
        return foo(_trans);
    }
}

const float *test = barInstance->play(); //Complains here
doSomething(test[0],test[1],test[2])

Now this complain goes away when I do this instead

const foo *test = barInstance->play(); 

Why does that complain go away when i replace float* with foo*. I know there is an implicit construction going on with float* why does the sanitizer complain about that ? The code in both cases works fine.

Aucun commentaire:

Enregistrer un commentaire