From f3eef5c4ddfa54fa7f6d155e90721cde318cc6f2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 Mar 2018 16:06:53 +0200 Subject: Ignore NULL arguments in process_run --- libbutl/process.mxx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libbutl/process.mxx b/libbutl/process.mxx index 39a5d92..4a9c3cd 100644 --- a/libbutl/process.mxx +++ b/libbutl/process.mxx @@ -486,8 +486,9 @@ LIBBUTL_MODEXPORT namespace butl // // The A arguments can be anything convertible to const char* via the // overloaded process_arg_as() (see below). Out of the box you can use const - // char*, std::string, path/dir_path, (as well as [small_]vector[_view] of - // these), and numeric types (as well as optional of all the above). + // char* (with NULL values ignored), std::string, path/dir_path, (as well as + // [small_]vector[_view] of these), numeric types, as well as optional of + // all the above with absent arguments ignored. // struct process_env { @@ -642,8 +643,13 @@ LIBBUTL_MODEXPORT namespace butl // char[N] // - inline const char* - process_arg_as (const char* s, std::string&) {return s;} + template + inline void + process_args_as (V& v, const char* s, std::string&) + { + if (s != nullptr) + v.push_back (s); + } template inline const char* @@ -699,7 +705,8 @@ LIBBUTL_MODEXPORT namespace butl process_args_as (V& v, const std::vector& vs, std::string&) { for (const char* s: vs) - v.push_back (s); + if (s != nullptr) + v.push_back (s); } template @@ -707,7 +714,8 @@ LIBBUTL_MODEXPORT namespace butl process_args_as (V& v, const small_vector& vs, std::string&) { for (const char* s: vs) - v.push_back (s); + if (s != nullptr) + v.push_back (s); } template @@ -715,7 +723,8 @@ LIBBUTL_MODEXPORT namespace butl process_args_as (V& v, const vector_view& vs, std::string&) { for (const char* s: vs) - v.push_back (s); + if (s != nullptr) + v.push_back (s); } } -- cgit v1.1