this post was submitted on 24 Dec 2023
41 points (86.0% liked)

Rust

6049 readers
34 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 21 points 11 months ago (1 children)

Dangling pointers, double frees and the like, mostly. Tell me you haven't run into those and I'll laugh in your face and call you a liar.

[–] lysdexic -2 points 11 months ago* (last edited 11 months ago) (1 children)

Dangling pointers, double frees and the like, mostly.

Those are bugs you wrote in. UB is not the problem. Your code is the problem.

Tell me you haven’t run into those and I’ll laugh in your face and call you a liar.

I ran into bugs. Do you understand that UB is not the problem if you're pushing broken code? It's not the C++ standard that's messing up if you're writing in use-after-free bugs.

The irony of your comment is that some implementations take advantage of UB to prevent programs from crashing and actually continue to work in some scenarios such as use-after-free and even dereferencing null pointers. But that's not caused by UB, is it? Those problems are caused by developers like you and me who didn't knew what they were doing and even failed to either pay attention to the errors flagged by compiler and static code analysis tools, or even failed to onboard one.

I mean, think about it for a second. Let's say we have a magic wand that can update any C and C++ standard version of your choosing, and we specify that each and every single instance where behavior is left undefined is updated to specify that the program should automatically crash. Awesome, no more UB. What does this mean for your code? Is it now bug-free? Is it now working well after crashing all the time due to the code you added? What role did UB played in this mess?

Do you understand this?

I repeat: detractors just parrot undefined behavior as some kind of gotcha in ways I’m not even sure they fully understand.

[–] [email protected] 2 points 11 months ago

some implementations take advantage of UB to prevent programs from crashing and allow them to continue after encountering a UAF etc.

Could you provide examples of this?