Skip to content

Commit

Permalink
en: Add clarification in post
Browse files Browse the repository at this point in the history
More precisely, in the
2023-08-19-why-c-is-a-dangerous-programming-language post post. When
skimming through this now again, I realize that the way it's written
might not be entirely clear to people who are unfamiliar with reading C
code.
  • Loading branch information
perlun committed Jul 21, 2024
1 parent 5b8f667 commit 23858b7
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ What?? Why?! I don’t understand anything. I left the project at the end of the
Then, the morning after when I was still in bed, I realized what was probably happening. It was a typical “C mistake”.
Remember my `__wrap_puts` method above? Take a close look at it again. It takes a parameter and saves the value of this parameter for later use. Then look at my `print()` method above: it declares a **stack variable**, builds up the correct string inside this variable, then calls `puts()`... and then returns.
Remember my `__wrap_puts` method above? Take a close look at it again. It takes a parameter and saves the value of this parameter for later use. Then look at my `print()` method above: it declares a **stack variable** (`char formatted_number[length + 1]`), builds up the correct string inside this
variable, then calls `puts()`... and then returns.
I've highlighted "stack variable" here, because this is precisely the problem here. _Pointers to the stack cannot be saved like this_, it's doomed to fail. Unfortunately, the stack will be overwritten between the `puts()` call and the method which checks the `captured_output` content.
Expand Down

0 comments on commit 23858b7

Please sign in to comment.