File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
bindings/python/google_benchmark Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,18 @@ namespace {
1414namespace nb = nanobind;
1515
1616std::vector<std::string> Initialize (const std::vector<std::string>& argv) {
17- // The `argv` pointers here become invalid when this function returns, but
18- // benchmark holds the pointer to `argv[0]`. We create a static copy of it
19- // so it persists, and replace the pointer below.
20- static std::string executable_name (argv[0 ]);
2117 std::vector<char *> ptrs;
2218 ptrs.reserve (argv.size ());
2319 for (auto & arg : argv) {
2420 ptrs.push_back (const_cast <char *>(arg.c_str ()));
2521 }
26- ptrs[0 ] = const_cast <char *>(executable_name.c_str ());
22+ if (!ptrs.empty ()) {
23+ // The `argv` pointers here become invalid when this function returns, but
24+ // benchmark holds the pointer to `argv[0]`. We create a static copy of it
25+ // so it persists, and replace the pointer below.
26+ static std::string executable_name (argv[0 ]);
27+ ptrs[0 ] = const_cast <char *>(executable_name.c_str ());
28+ }
2729 int argc = static_cast <int >(argv.size ());
2830 benchmark::Initialize (&argc, ptrs.data ());
2931 std::vector<std::string> remaining_argv;
You can’t perform that action at this time.
0 commit comments