this post was submitted on 31 Aug 2025
316 points (96.5% liked)
Programmer Humor
26095 readers
1455 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
This is the code I used:
Without getting too critical of your code (congrats BTW), never use
strcpy
instead usestrlcpy
.strcpy
will happily allow you to create buffer overflows (a common challenge with C) which will cause your application to crash.You'll find more details here.
Good luck!
Thanks, I did not knew this. I always appreciate constructive criticism. I am quite new to C so theres a shit ton of stuff I have never done or dont even know about.
And understand when you can use them...
I've seen too much code following this advice blindly that just does something like
strncpy(dst, src, strlen(src))
I found the mistake. Since the country code char array only has a size of 2 it overwrites the \0 char causing the memory to leak.
Usually what's meant by a memory leak is memory that's allocated but never freed. Writing outside of array allocation would usually be considered an overflow. Which sounds kinda similar but is not the same.
Bingo. I thought something probably happened to your terminator.
This could make for a fun reverse engineering CTF challenge.