Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

most difficult-to-find errors in c++ [closed]

I am well aware, that there will probably not be "the one most difficult to find error in c++", but I am still interested in what other people can think of / may have already encountered.

The idea for this question arose during a discussion with a friend. We agreed, that it must be rather simple to sabotage a cpp project by delierately including errors in the source code that you submit... But the best thing we could think of was to use uninitialized variables (leading to random segmentation faults at runtime). I am sure there are better ways...?!

Wanted characteristics of the faulty code:

  • must look like valid code on first sight
  • must not stop the code from compiling (too obvious)
  • if possible the error should look like it might just have been a mistake (should it ever be found)
  • the error must be grave enough to stop the software from shipping (e.g. random seg faults, logical malfunction of the code etc.)

Still, while it must be noticeable, it should not be obvious right after the submition of the code... Well, you get the idea.

Don't worry, our considerations are purely theoretical (we do not plan to sabotage any project). We simply considered this to be a nice enough thought experiment to share with others :-)

In short:

What is the most subtle way to sabotage sourcecode that might go unnoticed in a differential commit (like git) but will ultimately prevent a release of the software?

like image 444
example Avatar asked Jan 10 '13 23:01

example


People also ask

Which type of error is usually the most difficult to find?

Logical errors are more difficult to locate because they do not result in any error message. A logical error is a mistake in reasoning by the programmer, but it is not a mistake in the programming language.

What are the 3 types of error in programming?

When developing programs there are three types of error that can occur: syntax errors. logic errors. runtime errors.

What are the two major types of errors in the C language?

Conclusion. There are 5 different types of errors in C programming language: Syntax error, Run Time error, Logical error, Semantic error, and Linker error. Syntax errors, linker errors, and semantic errors can be identified by the compiler during compilation.

How many types of errors are there in C?

Errors are mainly 5 types that are Syntax errors, Run-time errors, Linker errors, Logical errors, and Logical errors.


1 Answers

Classic:

#define if while #define else 

buried in some header.


Jamming on @WhozCraig's comment, also:

#define true (!!(__LINE__ % 10)) 

Once every ten lines true won't be so true, but the compiled program's behavior will stay consistent... to change inexplicably when something changes in the sources.

Along this line:

#define for if(__LINE__ % 10) for  #define NULL (!(__LINE__ % 10)) 

Or what about:

#define virtual  

this will cause serious problems - but only when dynamic dispatch is used, which may make its detection much more problematic.


In a similar fashion:

#define dynamic_cast static_cast 

// Fail early, fail often #define throw std::abort(); 
like image 176
Matteo Italia Avatar answered Sep 21 '22 17:09

Matteo Italia