Defensive programming: Difference between revisions

Content deleted Content added
m v2.04 - Fix errors for CW project (Heading should begin with "=")
Line 26:
// ...
}</syntaxhighlight>
The function will result in undefined behavior when the input is over 1000 characters. Some novice programmers may not feel that this is a problem, supposing that no user will enter such a long input. This particular bug demonstrates a vulnerability which enables [[buffer overflow]] [[exploit (computer security)|exploit]]s. Here is a solution to this example:
 
<syntaxhighlight lang="c">int secure_programming(char *input) {