notify: don't forget terminating NULL when patching notify helper's argv

This commit is contained in:
Daniel Eklöf 2024-07-31 18:31:18 +02:00
parent 76ac910b11
commit 18b87b2e20
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -476,18 +476,21 @@ notify_notify(struct terminal *term, struct notification *notif)
if (action_argc == 0) { if (action_argc == 0) {
free(argv[i]); free(argv[i]);
memmove(&argv[i], &argv[i + 1], (argc - i - 1) * sizeof(argv[0]));
argv[argc--] = NULL; /* Remove ${command-arg}, but include terminating NULL */
memmove(&argv[i], &argv[i + 1], (argc - i) * sizeof(argv[0]));
argc--;
break; break;
} }
/* Remove the "${action-arg}" entry, add all actions argument from earlier */ /* Remove the "${action-arg}" entry, add all actions argument
argv = xrealloc(argv, (argc + action_argc - 1) * sizeof(argv[0])); from earlier, but include terminating NULL */
argv = xrealloc(argv, (argc + action_argc) * sizeof(argv[0]));
/* Move remaining arguments to after the action arguments */ /* Move remaining arguments to after the action arguments */
memmove(&argv[i + action_argc], memmove(&argv[i + action_argc],
&argv[i + 1], &argv[i + 1],
(argc - (i + 1)) * sizeof(argv[0])); (argc - i) * sizeof(argv[0])); /* Include terminating NULL */
free(argv[i]); /* Free xstrdup("${action-arg}"); */ free(argv[i]); /* Free xstrdup("${action-arg}"); */
@ -501,10 +504,11 @@ notify_notify(struct terminal *term, struct notification *notif)
argc--; /* The ${action-arg} option has been removed */ argc--; /* The ${action-arg} option has been removed */
break; break;
} }
LOG_DBG("notify command:"); LOG_DBG("notify command:");
for (size_t i = 0; i < argc; i++) for (size_t i = 0; i < argc; i++)
LOG_DBG(" argv[%zu] = \"%s\"", i, argv[i]); LOG_DBG(" argv[%zu] = \"%s\"", i, argv[i]);
xassert(argv[argc] == NULL);
int stdout_fds[2] = {-1, -1}; int stdout_fds[2] = {-1, -1};
if (track_notification) { if (track_notification) {