NetBSD Problem Report #53281

From www@NetBSD.org  Sat May 12 14:56:10 2018
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 71D647A1BC
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 12 May 2018 14:56:10 +0000 (UTC)
Message-Id: <20180512145609.7E6327A26F@mollari.NetBSD.org>
Date: Sat, 12 May 2018 14:56:09 +0000 (UTC)
From: coypu@sdf.org
Reply-To: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Subject: aligned_alloc UB behaviour is much harsher than other implementations
X-Send-Pr-Version: www-1.0

>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:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat May 12 15:00:00 +0000 2018
>Closed-Date:    Tue Jun 19 01:53:27 +0000 2018
>Last-Modified:  Tue Jun 19 01:53:27 +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:

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Tue, 19 Jun 2018 01:53:27 +0000
State-Changed-Why:
People seem to disagree with being more lenient with explicit UB.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.