c++ - Calling Function Overwrites Value -


i have several configuration flags implementing structs. create object. call method of object flag, triggers comparison between 2 flags. however, time, 1 of flags has been overwritten somehow.

to clarify, here's simplified version of code should illustrate i'm seeing:

class flag_type { unsigned int flag; /*more stuff*/ }; flag_type flag1 flag_type flag2  class myobject {     public:         void method1(const flag_type& flag_arg) {             //conditionals, , then:             const flag_type flag_args[2] = {flag_arg,flag_arg};             method2(flag_args);         }         void method2(const flag_type flag_args[2]) {             //conditionals, , then:             method3(flag_args[0]);         }         void method3(const flag_type& flag_arg) { //actually in superclass             //stuff             if (flag_arg==flag1) { /*stuff*/ }             //stuff         } };  int main(int argc, const char* argv[]) {     //in functions called main:     myobject* obj = new myobject();      //later in other functions:     obj->method1(flag1); } 

with debugger , print statements, can confirm both flag1 , flag_arg/flag_args fine in both "method1" , "method2". however, when method3, "flag1.flag" has been corrupted, comparison fails.

now, although i'm stellar not doing it, , passes msvc's static code analysis on strictest settings, me looks behavior of buffer overrun.

i haven't found such error looking, of course 1 doesn't. question is
a: screwing somewhere else? realize i'm not sharing real code, missing already? scheme worked before before rewrote large portion of code.
b: there easier way picking through code more until find it? code cross-platform, i'm setting check valgrind on ubuntu box.

thanks tried help. though, should noted code for clarification purposes only; typed scratch show was happening; not compile. in retrospect, realize wasn't fair ask people solve on little information--though actual question "is there easier way picking through code more carefully" didn't concern solving problem--just how approach it.

as question, on ubuntu linux, got "stack smashing" told me more or less problem occurred. interestingly, traceback stack smashing helpful. long story short, embarrassingly basic error; strcpy overflowing (in operators ~, | , &, flags have debug string set way). @ least wasn't me wrote code. use strncpy, people :p


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -