Calling Function Overwrites Value
<p>I have several configuration flags that I am implementing as structs.  I create an object.  I call a method of the object with a flag, which eventually triggers a comparison between two flags.  However, by this time, one of the flags has been overwritten somehow.</p>

<p>To clarify, here's a VERY simplified version of the code that should illustrate what I'm seeing:</p>

<pre><code>class flag_type { unsigned int flag; /*more stuff*/ };
flag_type FLAG1
flag_type FLAG2

class MyObject {
    public:
        void method1(const flag_type&amp; flag_arg) {
            //conditionals, and then:
            const flag_type flag_args[2] = {flag_arg,flag_arg};
            method2(flag_args);
        }
        void method2(const flag_type flag_args[2]) {
            //conditionals, and then:
            method3(flag_args[0]);
        }
        void method3(const flag_type&amp; flag_arg) { //Actually in a superclass
            //stuff
            if (flag_arg==FLAG1) { /*stuff*/ }
            //stuff
        }
};

int main(int argc, const char* argv[]) {
    //In some functions called by main:
    MyObject* obj = new MyObject();

    //Later in some other functions:
    obj-&gt;method1(FLAG1);
}
</code></pre>

<p>With a debugger and print statements, I can confirm that both FLAG1 and flag_arg/flag_args are fine in both "method1" and "method2".  However, when I get to method3, "FLAG1.flag" has been corrupted, so the comparison fails.</p>

<p>Now, although I'm usually stellar about not doing it, and it passes MSVC's static code analysis on strictest settings, this to me looks like the behavior of a buffer overrun.</p>

<p>I haven't found any such error by looking, but of course one usually doesn't.  My question is<br/>A: Am I screwing up somewhere else?  I realize I'm not sharing any real code, but am I missing something already?  This scheme worked before before I rewrote a large portion of the code.<br/>
B: Is there an easier way than picking through the code more carefully until I find it?  The code is cross-platform, so I'm already setting it up to check with Valgrind on an Ubuntu box.</p>
