Who finds it first... [closed] : [modified]
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
The language looks alien to me :doh: Let me guess: If stDestPath is empty, you get buggered in
moveFilesToDest(&stDestPath);
? I find it strange that examineFile returns a bunch of negative error codes. :~Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
VuNic wrote:
if((stSourcePath.size==0)||(stDestPath.size==0)) { ... }
I guess the bug is here as the method continues when either of the strings is of zero length which wouldn't make sende after all. So if stSourcePath has zero length then I'm curious what examineFile will return.
-
The language looks alien to me :doh: Let me guess: If stDestPath is empty, you get buggered in
moveFilesToDest(&stDestPath);
? I find it strange that examineFile returns a bunch of negative error codes. :~Cheers, Vıkram.
After all is said and done, much is said and little is done.
Oops!missed to mention that it's about a syntax typo!! So no probs with function calls. And the strings involved in the code are all std::strings. The type of bug is similar(but not same!) to this if(x=n),[It should've been "=="] where the compiler doesn't report any syntax error, also at run time no exception would be thrown. So guess that :-D
-
VuNic wrote:
if((stSourcePath.size==0)||(stDestPath.size==0)) { ... }
I guess the bug is here as the method continues when either of the strings is of zero length which wouldn't make sende after all. So if stSourcePath has zero length then I'm curious what examineFile will return.
Ah good optimus! You've spotted the logical mistake I did when I put that code here and modified online. Sorry I've corrected the mistake. Look at the code again, you'd see it. Also check my reply to Vikram. Anyway you are dangerously close the bug! good luck :-D
-
Ah good optimus! You've spotted the logical mistake I did when I put that code here and modified online. Sorry I've corrected the mistake. Look at the code again, you'd see it. Also check my reply to Vikram. Anyway you are dangerously close the bug! good luck :-D
I'm not sure but doesn't push_back already take a reference while you are passing a pointer to it?
-
I'm not sure but doesn't push_back already take a reference while you are passing a pointer to it?
-
Hey no,k now I'm pushing the string's value inside the vector , no refs... So ignore it ;).. find the bug.. just a clue. It's related to std::strings. :-D
Never worked that much with std::string but I will keep track :-D
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
if((stSourcePath.size==0)||(stDestPath.size==0)) Isn't size a function?? It should probably be if((stSourcePath.size()==0)||(stDestPath.size()==0)) and you should be getting a compilation error?!!
"a child will grow up to become an adult, but you can never stop the adult from acting like a child"
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007 -
if((stSourcePath.size==0)||(stDestPath.size==0)) Isn't size a function?? It should probably be if((stSourcePath.size()==0)||(stDestPath.size()==0)) and you should be getting a compilation error?!!
"a child will grow up to become an adult, but you can never stop the adult from acting like a child"
-
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007 -
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007 -
Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P
Cheers, Vıkram.
After all is said and done, much is said and little is done.
There are many objects that expose values through member variables, so when you mix them up with the objects that uses functions to return values, you'll get confused. In particular when the object supports both ways.
Vikram A Punathambekar wrote:
But Swathi can have your beer; I'm a teetotaller.
Hey that's actually an apple juice filled in a beer cup ;P
-
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007admirm wrote:
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right?
says the guy with a typo in his user name - shouldn't it be
admin
? :laugh:Regards, mav -- Black holes are the places where God divided by 0...
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
That's why I use
std::string.length
:) (or was it length() :doh:) -
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.