4 ms·
Not sure what 'story' is intended to mean here. Is use-after-free undefined behaviour in Zig?
by MaxBarraclough 5y ago
Not sure what 'story' is intended to mean here. Is use-after-free undefined behaviour in Zig?
- blueblob 5y agoIs use-after-free ever really defined behavior?
- MaxBarraclough 5y agoThat would depend on the language and the libraries. You could roll your own 'safe' memory pool in C such that use-after-free doesn't produce undefined behaviour. You'd still have a bug, but it wouldn't have to invoke UB at the level of the C programming language.
- matheusmoreira 5y agoYes. Undefined behavior exists only in standards. It's perfectly possible for implementations to define everything. https://www.joelonsoftware.com/2004/06/13/how-microsoft-lost-the-api-war/ https://www.joelonsoftware.com/2004/06/13/how-microsoft-lost... > I first heard about this from one of the developers of the hit game SimCity, who told me that there was a critical bug in his application: > it used memory right after freeing it, a major no-no that happened to work OK on DOS but would not work under Windows where memory that is freed is likely to be snatched up by another running application right away. > The testers on the Windows team were going through various popular applications, testing them to make sure they worked OK, but SimCity kept crashing. > They reported this to the Windows developers, who disassembled SimCity, stepped through it in a debugger, found the bug, and added special code that checked if SimCity was running, and if it did, ran the memory allocator in a special mode in which you could still use memory after freeing it.
- deleted 5y ago[deleted]
- AnIdiotOnTheNet 5y agoThere isn't really anything in the language that prevents use-after-free, partially because allocation isn't even part of the language and exists entirely in userland code. However, IIRC the standard library does include an allocator that tries to detect use-after-free.
- skohan 5y agoIsn't that an intentional design decision in Zig? As far as I understood, Zig isn't trying to "solve" memory management, it's trying to provide manual memory management with better tools than C to help you do it right, but it's explicitly not trying to save you from yourself in this respect.
- pjmlp 5y agoExcept that C and C++ already provide similar tools, one just needs to actually enable them.
- MaxBarraclough 5y agoI don't follow. You recently pointed out to me that most of the serious security bugs in the Chromium codebase (C++) are rooted in memory-management. [0] It's no simple thing to fix these bugs. Not even Google can do so in their most treasured code. [0] https://news.ycombinator.com/item?id=26862330 https://news.ycombinator.com/item?id=26862330
- pjmlp 5y agoThe point being that Zig improves very little regarding that, because it is based on the same kind of tooling.
- matheusmoreira 5y ago> allocation isn't even part of the language It's not supposed to be. In most cases, memory allocation is an operating system concept. As a systems programming language, zig must not abstract this away from the programmer.