NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/53281: aligned_alloc UB behaviour is much harsher than other implementations
>Number: 53281
>Category: lib
>Synopsis: aligned_alloc UB behaviour is much harsher than other implementations
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat May 12 15:00:00 +0000 2018
>Originator: coypu
>Release: NetBSD 8.99.16
>Organization:
>Environment:
NetBSD planets 8.99.16 NetBSD 8.99.16 (GENERIC) #0: Tue May 8 12:54:21 IDT 2018 fly@planets:/home/fly/current/sys/arch/amd64/compile/GENERIC amd64
>Description:
The following program asserts in netbsd, but not with glibc.
#include <assert.h>
#include <stdlib.h>
int main() {
char * buf = aligned_alloc(32, 23);
assert(buf != NULL);
return 0;
}
C11 says:
J.2 Undefined behavior
1 The behavior is undefined in the following circumstances:
...
The alignment requested of the aligned_alloc function is not valid or not supported by the implementation, or the size requested is not an integral multiple of the alignment (7.22.3.1).
so it might be legal to implement as netbsd does, but probably inadvisable, if common C libraries don't.
The one case I saw (blosc) had a fallback for posix_memalign, but as C11 becomes more commonplace, people will likely prefer it and have no reason to make the fallback case, so we will suffer.
>How-To-Repeat:
>Fix:
Home |
Main Index |
Thread Index |
Old Index