Use a special type for opts->argv[] so that the whole array, and array entries, can both be NULL, and the array entries pointers to constant strings; and ensure that argv[] always has a NULL pointer on the end - all so argv can be passed to execvp() (#67).

This commit is contained in:
Andrew Wood
2026-03-19 22:57:41 +00:00
parent 29c65ad9e1
commit 04f99c4951
2 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -46,6 +46,8 @@ typedef enum {
PV_SIDE_BOTH /* monitor both sides */
} pvside_t;
typedef /*@null@*/ const char * argv_string;
/*
* Structure describing run-time options.
*
@@ -66,7 +68,7 @@ struct opts_s {
/*@keep@*/ /*@null@*/ char *extra_display; /* extra display specifier, if any */
/*@keep@*/ /*@null@*/ pid_t *watchfd_pid; /* array of processes to watch fds of */
/*@keep@*/ /*@null@*/ int *watchfd_fd; /* array of fds to watch in each one (0=all) */
/*@keep@*/ /*@null@*/ const char **argv; /* array of non-option arguments */
/*@keep@*/ /*@null@*/ argv_string *argv; /* array of non-option arguments */
size_t lastwritten; /* show N bytes last written */
off_t rate_limit; /* rate limit, in bytes per second */
size_t buffer_size; /* buffer size, in bytes (0=default) */
+4 -2
View File
@@ -92,12 +92,13 @@ void opts_free( /*@only@ */ opts_t opts)
/*
* Add a filename to the list of non-option arguments, returning false on
* error. The filename is not copied - the pointer is stored.
* error. The filename is not copied - the pointer is stored. The list is
* guaranteed to have a NULL after the last item.
*/
bool opts_add_file(opts_t opts, const char *filename)
{
/*@-branchstate@ */
if ((opts->argc >= opts->argv_length) || (NULL == opts->argv)) {
if (((1+opts->argc) >= opts->argv_length) || (NULL == opts->argv)) {
opts->argv_length = opts->argc + 10;
/*@-keeptrans@ */
opts->argv = realloc(opts->argv, opts->argv_length * sizeof(char *));
@@ -121,6 +122,7 @@ bool opts_add_file(opts_t opts, const char *filename)
*/
opts->argv[opts->argc++] = filename;
opts->argv[opts->argc] = NULL;
return true;
}