<html><head></head><body>Hi,<br><br>How do you test undefined behaviour? I think it's untestable by (lack of) definition.<br><br><div class="gmail_quote">Le 29 juillet 2019 09:19:22 GMT+03:00, Steve Lhomme <robux4@ycbcr.xyz> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">It seems that you are not testing failure when the code tries to align <br>to a value higher than max_align_t.<br><br>On 2019-07-26 21:20, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">vlc | branch: master | Rémi Denis-Courmont <remi@remlab.net> | Fri Jul 26 21:12:32 2019 +0300| [07e3b65d24cd84cbffe8f35f7e38b76546e80e8b] | committer: Rémi Denis-Courmont<br><br>compat: test heap allocation replacements<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"><a href="http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=07e3b65d24cd84cbffe8f35f7e38b76546e80e8b">http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=07e3b65d24cd84cbffe8f35f7e38b76546e80e8b</a><br></blockquote><hr>  compat/Makefile.am |   4 ++<br>  compat/test/heap.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++<br>  2 files changed, 109 insertions(+)<br><br>diff --git a/compat/Makefile.am b/compat/Makefile.am<br>index d709d565c5..cc1d33bb59 100644<br>--- a/compat/Makefile.am<br>+++ b/compat/Makefile.am<br>@@ -13,9 +13,13 @@ dummy.c:<br>  <br>  <br>  check_PROGRAMS = \<br>+ test_heap \<br>   test_strnstr<br>  <br>  TESTS = $(check_PROGRAMS)<br>+AM_TESTS_ENVIRONMENT = ASAN_OPTIONS="allocator_may_return_null=1"<br>  <br>+test_heap_SOURCES = test/heap.c<br>+test_heap_LDADD = libcompat.la<br>  test_strnstr_SOURCES = test/strnstr.c<br>  test_strnstr_LDADD = libcompat.la<br>diff --git a/compat/test/heap.c b/compat/test/heap.c<br>new file mode 100644<br>index 0000000000..a4933295ff<br>--- /dev/null<br>+++ b/compat/test/heap.c<br>@@ -0,0 +1,105 @@<br>+/*****************************************************************************<br>+ * aligned_alloc test case<br>+ *****************************************************************************<br>+ * Copyright © 2019 Rémi Denis-Courmont<br>+ *<br>+ * This program is free software; you can redistribute it and/or modify it<br>+ * under the terms of the GNU Lesser General Public License as published by<br>+ * the Free Software Foundation; either version 2.1 of the License, or<br>+ * (at your option) any later version.<br>+ *<br>+ * This program is distributed in the hope that it will be useful,<br>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>+ * GNU Lesser General Public License for more details.<br>+ *<br>+ * You should have received a copy of the GNU Lesser General Public License<br>+ * along with this program; if not, write to the Free Software Foundation,<br>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>+ *****************************************************************************/<br>+<br>+#include "config.h"<br>+#undef NDEBUG<br>+#include <assert.h><br>+#include <stdalign.h><br>+#include <stddef.h><br>+#include <stdint.h><br>+#include <stdlib.h><br>+#include <errno.h><br>+<br>+struct big_align_struct {<br>+    long long ll;<br>+    double d;<br>+};<br>+<br>+/* Supported alignments. Others are undefined (ISO C11 §7.22.3, §J.2). */<br>+static const size_t alignv[] = {<br>+    alignof (char),<br>+    alignof (short),<br>+    alignof (int),<br>+    alignof (long),<br>+    alignof (long long),<br>+    alignof (float),<br>+    alignof (double),<br>+    alignof (struct big_align_struct),<br>+    alignof (void *),<br>+    alignof (max_align_t),<br>+};<br>+<br>+static const size_t alignc = sizeof (alignv) / sizeof (alignv[0]);<br>+<br>+static void test_posix_memalign(size_t align, size_t size)<br>+{<br>+    void *p;<br>+    int val = posix_memalign(&p, align, size);<br>+<br>+    if (align >= sizeof (void *)) {<br>+        if (val == 0) {<br>+            assert(((uintptr_t)p & (align - 1)) == 0);<br>+            free(p);<br>+        }<br>+    } else<br>+        assert(val != 0);<br>+}<br>+<br>+int main(void)<br>+{<br>+    void *p;<br>+<br>+    /* aligned_alloc() */<br>+<br>+    for (size_t i = 0; i < alignc; i++) {<br>+        size_t align = alignv[i];<br>+<br>+        assert((align & (align - 1)) == 0); /* must be a power of two */<br>+<br>+        p = aligned_alloc(alignv[i], 0);<br>+        free(p); /* must free {aligned_,c,m,c,re}alloc() allocations */<br>+<br>+        for (size_t j = 0; j < alignc; j++) {<br>+             size_t size = alignv[j];<br>+<br>+             if (size < align)<br>+                 continue; /* size must be a multiple of alignment */<br>+<br>+             p = aligned_alloc(align, size);<br>+             assert(p != NULL); /* small non-zero bytes allocation */<br>+             assert(((uintptr_t)p & (align - 1)) == 0);<br>+             free(p);<br>+        }<br>+    }<br>+<br>+    /* posix_memalign() */<br>+<br>+    for (size_t i = 0; i < 21; i++) {<br>+        size_t align = (size_t)1 << i;<br>+<br>+        test_posix_memalign(align, 0);<br>+        test_posix_memalign(align, 1);<br>+        test_posix_memalign(align, align - 1);<br>+        test_posix_memalign(align, align);<br>+        test_posix_memalign(align, align * 2);<br>+    }<br>+<br>+    return 0;<br>+}<hr>vlc-commits mailing list<br>vlc-commits@videolan.org<br><a href="https://mailman.videolan.org/listinfo/vlc-commits">https://mailman.videolan.org/listinfo/vlc-commits</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>