From 9e1d96c1f265610ba9fa4f729b5aa66079d113f5 Mon Sep 17 00:00:00 2001 From: Kyriakos Nikolaos Gkorogiannis Date: Fri, 6 Oct 2017 07:27:32 -0700 Subject: [PATCH] [threadsafety] Fix exception thrown by list of actuals and formals not having the same length in some cases (C++?) Reviewed By: jberdine Differential Revision: D5995583 fbshipit-source-id: 2d3debf --- infer/src/checkers/ThreadSafety.ml | 2 +- .../cpp/threadsafety/variadic.cpp | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/cpp/threadsafety/variadic.cpp diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 74194500c..0f27f0fab 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -581,7 +581,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let open Domain in let formals, _ = FormalMap.make pdesc |> FormalMap.get_formals_indexes |> List.unzip in let fmls_actls = - List.zip_exn formals actuals + List.zip_exn formals (List.take actuals (List.length formals)) |> List.filter_map ~f:(fun (fml, act) -> match get_access_path act with Some path -> Some (fml, path) | _ -> None ) in diff --git a/infer/tests/codetoanalyze/cpp/threadsafety/variadic.cpp b/infer/tests/codetoanalyze/cpp/threadsafety/variadic.cpp new file mode 100644 index 000000000..e2220f0cf --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/threadsafety/variadic.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include +#include + +double average(int count, ...) { + va_list ap; + int j; + double sum = 0; + + va_start(ap, + count); /* Requires the last fixed parameter (to get the address) */ + for (j = 0; j < count; j++) { + sum += va_arg(ap, int); /* Increments ap to the next argument. */ + } + va_end(ap); + + return sum / count; +} + +int main(int argc, char const* argv[]) { + printf("%f\n", average(3, 1, 2, 3)); + return 0; +}