From 0dff431f9c96848229c4f0b26ec0466740f9f03e Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Fri, 7 Jun 2019 16:40:22 +0200 Subject: [PATCH] [NL] Prevent impl. conv. and unsigned overflow. The length of the passed initializer list is expected to be short, well below of 100 entries or so. --- NumLib/NamedFunctionCaller.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NumLib/NamedFunctionCaller.cpp b/NumLib/NamedFunctionCaller.cpp index 50c2d58b975..94c6fa84e4e 100644 --- a/NumLib/NamedFunctionCaller.cpp +++ b/NumLib/NamedFunctionCaller.cpp @@ -10,6 +10,7 @@ #include "NamedFunctionCaller.h" #include <algorithm> +#include <limits> #include "BaseLib/Algorithm.h" @@ -114,8 +115,10 @@ namespace NumLib { NamedFunctionCaller::NamedFunctionCaller( std::initializer_list<std::string> unbound_argument_names) - : _uninitialized(-1 - unbound_argument_names.size()) + : _uninitialized(-1 - static_cast<int>(unbound_argument_names.size())) { + assert(unbound_argument_names.size() < + static_cast<std::size_t>(std::numeric_limits<int>::max())); int idx = -1; for (auto arg : unbound_argument_names) { BaseLib::insertIfKeyUniqueElseError( -- GitLab