r/programminghorror • u/SolarisFalls • Jun 08 '26
c This uint 32 definition is actually 64 bits
Took me quite a while to debug this, considering I expected uint32 to be a... uint32?
321
Upvotes
r/programminghorror • u/SolarisFalls • Jun 08 '26
Took me quite a while to debug this, considering I expected uint32 to be a... uint32?
187
u/elperroborrachotoo Jun 08 '26
tuint32 == two int32, makes sense, no? 🙃
50
u/paulstelian97 Jun 08 '26
What the muffin
There any #ifdef issues?
27
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jun 08 '26
So how much of that shit before you get to the actual core language types?
11
u/anxxa Jun 08 '26
Pretty bad, but how does that lead to a stack overflow? Were you using
sizeof(tuint32)to write into a fixed-size buffer that usessizeof(uint32_t)/hardcoded 4?10
u/sawkonmaicok Jun 08 '26
Uh oh. Someone is trying to implement their own ASN1 decoder. Fine if a hobby project but if this is in production, then you are better off using just an off-the-shelf parser instead.
2
u/MrMikeHigginbottom Jun 09 '26
The first question that popped into my head was "Is C the smart choice for safety critical stuff?"
2
u/daHaus Jun 08 '26
This is why I've grown to abhor LLM generated code and why they're, somehow, not actually improving productivity.
The only time an actual person would do something like this was out of spite
-23
u/adenosine-5 Jun 08 '26
C++ likes to troll its users in this way - unless you specify that you really, absolutely, surely, forrealthistime want 32bit integers, the system can do pretty much whatever.
You can have int that is 16 bits, or long that is 32 bits, etc
Because consistency is overrated or something i guess :)
1
u/Bixkitts Jun 13 '26
I'm near the beginning of my career programming machines that want to dismember people if we let them.
I have to deal with horrible code a lot! (my own too)
I think it stems from learned archaic/bad/misunderstood techniques, and lack of communication with people that
could point them out before they become core parts of the software.
This includes a worrying amount of basic language features that get misused, or unused.
If I may posit question or two,
may I ask where you think bad code comes from and how you prevent it's proliferation in a team?
By bad code, I mean like the bad macro/type definitions in your example.
Particularly in a small team, where the priority is avoiding unnecessary limb loss,
and having the software run for 20+ years.
And what's the first thing you would institute, presuming we have none (we don't):
Code reviews? Tests? Good source control practices? Comprehensive knowledge of language and stdlib features? Catching off-by-one errors? Some secret, underappreciated fourth option?
Thanks!