From 86e4ecb99fa626a389cee96fb034c8c5b1c0121b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 11 Nov 2020 17:44:24 +0100 Subject: Use C11 if possible --- .clang-tidy | 1 + wscript | 4 +++- zix/btree.c | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a454239..1e42e8e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,6 +7,7 @@ Checks: > -cert-err34-c, -cert-msc30-c, -cert-msc50-cpp, + -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -cppcoreguidelines-init-variables, -google-readability-casting, -hicpp-multiway-paths-covered, diff --git a/wscript b/wscript index 1ae541c..ab2f639 100644 --- a/wscript +++ b/wscript @@ -36,7 +36,9 @@ def options(ctx): def configure(conf): conf.load('compiler_c', cache=True) conf.load('autowaf', cache=True) - autowaf.set_c_lang(conf, 'c99') + + if not autowaf.set_c_lang(conf, 'c11', mandatory=False): + autowaf.set_c_lang(conf, 'c99') conf.env.update({ 'BUILD_BENCH': Options.options.bench, diff --git a/zix/btree.c b/zix/btree.c index 3dc2d57..302ab87 100644 --- a/zix/btree.c +++ b/zix/btree.c @@ -1,5 +1,5 @@ /* - Copyright 2011-2019 David Robillard + Copyright 2011-2020 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -49,6 +49,11 @@ struct ZixBTreeNodeImpl { ZixBTreeNode* children[ZIX_BTREE_INODE_VALS + 1]; // Nonexistent for leaves }; +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) +static_assert(sizeof(ZixBTreeNode) == ZIX_BTREE_PAGE_SIZE, ""); +#endif + typedef struct { ZixBTreeNode* node; unsigned index; @@ -99,7 +104,11 @@ print_tree(const ZixBTreeNode* parent, const ZixBTreeNode* node, int level) ZIX_PRIVATE ZixBTreeNode* zix_btree_node_new(const bool leaf) { +#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \ + (defined(__cplusplus) && __cplusplus >= 201103L)) assert(sizeof(ZixBTreeNode) == ZIX_BTREE_PAGE_SIZE); +#endif + ZixBTreeNode* node = (ZixBTreeNode*)malloc(sizeof(ZixBTreeNode)); if (node) { node->is_leaf = leaf; -- cgit v1.2.1