diff options
author | Barnabás Pőcze <barnabas.pocze@ideasonboard.com> | 2025-03-24 12:39:11 +0100 |
---|---|---|
committer | Barnabás Pőcze <barnabas.pocze@ideasonboard.com> | 2025-06-09 15:25:22 +0200 |
commit | 0a591eaf8c36ffd34dc0d69e6221c4fe88fd4a73 (patch) | |
tree | becfaf6e1a7ef538ca9ef31d4b915aff3d90d4ab | |
parent | 081554db346a9ff2e610be1cff8d463ff3bc3b8a (diff) |
libcamera: process: Misc. cleanup around `execv()`
Firstly, get the number of arguments first, and use that to determine the
size of the allocation instead of retrieving it twice.
Secondly, use `const_cast` instead of a C-style cast when calling `execv()`.
Third, use `size_t` to match the type of `args.size()`.
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | src/libcamera/process.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index d836fb07..f4e4b004 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -279,14 +279,15 @@ int Process::start(const std::string &path, if (file && strcmp(file, "syslog")) unsetenv("LIBCAMERA_LOG_FILE"); - const char **argv = new const char *[args.size() + 2]; - unsigned int len = args.size(); + const size_t len = args.size(); + auto argv = std::make_unique<const char *[]>(len + 2); + argv[0] = path.c_str(); - for (unsigned int i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) argv[i + 1] = args[i].c_str(); argv[len + 1] = nullptr; - execv(path.c_str(), (char **)argv); + execv(path.c_str(), const_cast<char **>(argv.get())); _exit(EXIT_FAILURE); } |