0.0/10
verdict: needs_serious_help
"Return of the dangling pointer of doom!"
lang: C·4 lines
//your_submission
DanglingPointerDisaster.c
int* getLocalValue() {
int tempValue = 42;
return &tempValue;
}//detailed_analysis
!
Dangling Pointer
You're returning the address of a local variable, which is immediately destroyed when the function ends. This is like giving someone a map to a house that doesn't exist, but hey, at least you tried?
!
Memory Safety
Your code is a crash waiting to happen. The caller will try to access memory that's already been freed, causing a segfault or other undefined behavior. It's like playing a game of Russian roulette, but with pointers!
?
Code Smell
Why are you even returning a pointer to an int? Just return the int itself! This is like trying to solve a simple math problem with a blowtorch and a sledgehammer.
//suggested_fix
DanglingPointerDisaster_fixed.c
+int getLocalValue() {
+ return 42;
+}