From: Richard Kreckel Date: Tue, 7 Apr 2020 21:56:25 +0000 (+0200) Subject: [PATCH] Check number of parameters when reading function from archive. X-Git-Tag: release_1-7-9~6 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=3d5c30286146e192d4c22cbb989997cdfe306200 [PATCH] Check number of parameters when reading function from archive. Functions where looked up by their function name in archives. However, some functions have overloads for different numbers of parameters ('zeta', 'G', 'psi'). Reading archives could pick the wrong overload. Fixed by requiring that the actual number of function parameters in the archive node must equal the function's declared number of parameters. Thanks to Feng Feng for reporting this problem. --- diff --git a/ginac/function.cppy b/ginac/function.cppy index 2e126640..6739eb9e 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -259,18 +259,20 @@ function::function(unsigned ser, exvector && v) void function::read_archive(const archive_node& n, lst& sym_lst) { inherited::read_archive(n, sym_lst); - // Find serial number by function name + // Find serial number by function name and number of parameters + unsigned np = seq.size(); std::string s; if (n.find_string("name", s)) { unsigned int ser = 0; for (auto & it : registered_functions()) { - if (s == it.name) { + if (s == it.name && np == registered_functions()[ser].nparams) { serial = ser; return; } ++ser; } - throw (std::runtime_error("unknown function '" + s + "' in archive")); + throw (std::runtime_error("unknown function '" + s + + "' with " + std::to_string(np) + " parameters in archive")); } else throw (std::runtime_error("unnamed function in archive")); }