3 ms·
If you call free((void *)-1) in C code, it will very likely crash, but it will crash in libc, not your program. Is that a bug in libc?
by tedunangst 5y ago
If you call free((void *)-1) in C code, it will very likely crash, but it will crash in libc, not your program. Is that a bug in libc?
- Thorrez 5y agoThat's documented undefined behavior. Is it documented undefined behavior to feed bad IR into LLVM?
- scatters 5y agoOf course. If there's an input checking mode, and you disable the checks, then you're guaranteeing that you won't supply invalid input.
- MaxBarraclough 5y agoI think even deriving the argument might invoke undefined behaviour here, but I'm not certain. If I understand correctly, it's undefined behaviour to do this: int *ptr = (int*)42; As, in order to avoid undefined behaviour, ptr should only be assigned a valid address of an int, or the 'address' one past the end of an array of int, or NULL (logical zero). It's possible things are different when the type is void*, I'm not certain.
- tedunangst 5y agoMake it free(free) if you want it to be a valid pointer.
- kelnos 5y agoNo, because the defined contract for free() is that you pass it a pointer that was previously returned from malloc(), that you don't try to free() it twice, etc.