Browse Source

Allocate (argc + 1) for the service arguments, with calloc

It was assumed that getopt checks argc count and does not require
null-terminated argv pointer to determine argv end for optional
parameter.
That is wrong.
Add null-terminated latest argv.

Fixes #246
pull/256/head
ValdikSS 3 years ago
parent
commit
8deacbc438
  1. 2
      src/service.c

2
src/service.c

@ -30,7 +30,7 @@ int service_register(int argc, char *argv[])
*/
if (!service_argc && !service_argv) {
service_argc = argc;
service_argv = malloc(sizeof(void*) * (size_t)argc);
service_argv = calloc(sizeof(void*), (size_t)(argc + 1));
for (i = 0; i < argc; i++) {
service_argv[i] = strdup(argv[i]);
}

Loading…
Cancel
Save