From caec384ed0bc049163857124a93ac70f3ae1aee6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 27 May 2020 16:30:44 +0200 Subject: [PATCH] archive/ArchiveList, input/Registry: avoid zero-sized array Some more `-Wpedantic` fixups. --- src/archive/ArchiveList.cxx | 6 +++++- src/input/Registry.cxx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/archive/ArchiveList.cxx b/src/archive/ArchiveList.cxx index 5c1344a0a..25a4a72f9 100644 --- a/src/archive/ArchiveList.cxx +++ b/src/archive/ArchiveList.cxx @@ -43,8 +43,12 @@ const ArchivePlugin *const archive_plugins[] = { nullptr }; +static constexpr std::size_t n_archive_plugins = std::size(archive_plugins) - 1; + /** which plugins have been initialized successfully? */ -static bool archive_plugins_enabled[std::size(archive_plugins) - 1]; +/* the std::max() is just here to avoid a zero-sized array, which is + forbidden in C++ */ +static bool archive_plugins_enabled[std::max(n_archive_plugins, std::size_t(1))]; #define archive_plugins_for_each_enabled(plugin) \ archive_plugins_for_each(plugin) \ diff --git a/src/input/Registry.cxx b/src/input/Registry.cxx index 6fd2fe424..f5a37f2a1 100644 --- a/src/input/Registry.cxx +++ b/src/input/Registry.cxx @@ -83,7 +83,11 @@ const InputPlugin *const input_plugins[] = { nullptr }; -bool input_plugins_enabled[std::size(input_plugins) - 1]; +static constexpr std::size_t n_input_plugins = std::size(input_plugins) - 1; + +/* the std::max() is just here to avoid a zero-sized array, which is + forbidden in C++ */ +bool input_plugins_enabled[std::max(n_input_plugins, std::size_t(1))]; bool HasRemoteTagScanner(const char *uri) noexcept