Code quality: Fix some cppcheck messages

This commit addresses these kind of errors:

portability: Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]

Reason is that C does not guarantee that all pointer types are the same
size. See C99 6.2.5(27). cppcheck requires some sort of cast when NULL
is used as the last argument in a variadic list.
This commit is contained in:
matt335672
2026-02-20 12:06:05 +00:00
committed by firewave
parent 94c0024c3b
commit d3bfe802cc
10 changed files with 41 additions and 31 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ list_add_strdup_multi(struct list *self, ...)
int rv = 1; int rv = 1;
va_start(ap, self); va_start(ap, self);
while ((s = va_arg(ap, const char *)) != NULL) while ((s = va_arg(ap, const char *)) != LIST_ADD_STRDUP_TERM)
{ {
if (!list_add_strdup(self, s)) if (!list_add_strdup(self, s))
{ {
+5 -1
View File
@@ -149,12 +149,16 @@ list_add_strdup(struct list *self, const char *str);
* *
* This is a convenience function for a common operation * This is a convenience function for a common operation
* @param self List to append to * @param self List to append to
* @param ... Strings to append. Terminate the list with a NULL. * @param ... Strings to append. Terminate the list with LIST_ADD_STRDUP_TERM
* *
* @result 0 if any memory allocation failure occurred. In this case * @result 0 if any memory allocation failure occurred. In this case
* the list is unchanged. * the list is unchanged.
*/ */
/*
* We need a typed terminator to guarantee the stack object is the
* correct size (cf C99 std 6.2.5(12) for static checkers */
#define LIST_ADD_STRDUP_TERM ((const char *)0)
int int
list_add_strdup_multi(struct list *self, ...); list_add_strdup_multi(struct list *self, ...);
+4 -4
View File
@@ -399,7 +399,7 @@ prepare_xorg_xserver_params(const struct session_parameters *s,
list_add_strdup_multi(params, list_add_strdup_multi(params,
xserver, screen, xserver, screen,
"-auth", authfile, "-auth", authfile,
NULL); LIST_ADD_STRDUP_TERM);
/* additional parameters from sesman.ini file */ /* additional parameters from sesman.ini file */
list_append_list_strdup(g_cfg->xorg_params, params, 1); list_append_list_strdup(g_cfg->xorg_params, params, 1);
@@ -451,7 +451,7 @@ prepare_xvnc_xserver_params(const struct session_parameters *s,
"-auth", authfile, "-auth", authfile,
"-geometry", geometry, "-geometry", geometry,
"-depth", depth, "-depth", depth,
NULL); LIST_ADD_STRDUP_TERM);
if (passwd_file != NULL) if (passwd_file != NULL)
{ {
@@ -459,7 +459,7 @@ prepare_xvnc_xserver_params(const struct session_parameters *s,
env_check_password_file(passwd_file, guid_str); env_check_password_file(passwd_file, guid_str);
list_add_strdup_multi(params, list_add_strdup_multi(params,
"-rfbauth", passwd_file, "-rfbauth", passwd_file,
NULL); LIST_ADD_STRDUP_TERM);
} }
else if (port != NULL) else if (port != NULL)
{ {
@@ -478,7 +478,7 @@ prepare_xvnc_xserver_params(const struct session_parameters *s,
"-rfbunixpath", port, "-rfbunixpath", port,
"-rfbunixmode", sock_mode, "-rfbunixmode", sock_mode,
"-SecurityTypes", "None", "-SecurityTypes", "None",
NULL); LIST_ADD_STRDUP_TERM);
} }
/* additional parameters from sesman.ini file */ /* additional parameters from sesman.ini file */
+2 -1
View File
@@ -67,7 +67,8 @@ make_xwait_command(int display)
cmd->auto_free = 1; cmd->auto_free = 1;
g_snprintf(displaystr, sizeof(displaystr), ":%d", display); g_snprintf(displaystr, sizeof(displaystr), ":%d", display);
if (!list_add_strdup_multi(cmd, exe, "-d", displaystr, NULL)) if (!list_add_strdup_multi(cmd, exe, "-d", displaystr,
LIST_ADD_STRDUP_TERM))
{ {
list_delete(cmd); list_delete(cmd);
cmd = NULL; cmd = NULL;
+2 -1
View File
@@ -69,7 +69,8 @@ create_exec_args_add_entries(struct list *args)
if (g_strcmp(g_cfg->sesman_ini, DEFAULT_SESMAN_INI) != 0) if (g_strcmp(g_cfg->sesman_ini, DEFAULT_SESMAN_INI) != 0)
{ {
if (!list_add_strdup_multi(args, "-c", g_cfg->sesman_ini, NULL)) if (!list_add_strdup_multi(args, "-c", g_cfg->sesman_ini,
LIST_ADD_STRDUP_TERM))
{ {
return 0; return 0;
} }
+8 -7
View File
@@ -152,32 +152,33 @@ sesman_process_params(int argc, char **argv,
value = ""; value = "";
} }
if (nocase_matches(option, "-help", "--help", "-h", NULL)) if (nocase_matches(option, "-help", "--help", "-h", (const char *)0))
{ {
startup_params->help = 1; startup_params->help = 1;
} }
else if (nocase_matches(option, "-kill", "--kill", "-k", NULL)) else if (nocase_matches(option, "-kill", "--kill", "-k",
(const char *)0))
{ {
startup_params->mode = SSM_KILL_DAEMON; startup_params->mode = SSM_KILL_DAEMON;
} }
else if (nocase_matches(option, "-reload", "--reload", "-r", NULL)) else if (nocase_matches(option, "-reload", "--reload", "-r", (const char *)0))
{ {
startup_params->mode = SSM_RELOAD_DAEMON; startup_params->mode = SSM_RELOAD_DAEMON;
} }
else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n", else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n",
"-nd", "--nd", "-ns", "--ns", NULL)) "-nd", "--nd", "-ns", "--ns", (const char *)0))
{ {
startup_params->no_daemon = 1; startup_params->no_daemon = 1;
} }
else if (nocase_matches(option, "-v", "--version", NULL)) else if (nocase_matches(option, "-v", "--version", (const char *)0))
{ {
startup_params->version = 1; startup_params->version = 1;
} }
else if (nocase_matches(option, "--dump-config", NULL)) else if (nocase_matches(option, "--dump-config", (const char *)0))
{ {
startup_params->dump_config = 1; startup_params->dump_config = 1;
} }
else if (nocase_matches(option, "-c", "--config", NULL)) else if (nocase_matches(option, "-c", "--config", (const char *)0))
{ {
index++; index++;
startup_params->sesman_ini = value; startup_params->sesman_ini = value;
+1 -1
View File
@@ -133,7 +133,7 @@ START_TEST(test_list__simple_strdup_multi)
list_add_strdup_multi(lst, list_add_strdup_multi(lst,
"0", "1", "2", "3", "4", "5", "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "10", "11", "6", "7", "8", "9", "10", "11",
NULL); LIST_ADD_STRDUP_TERM);
ck_assert_int_eq(lst->count, 12); ck_assert_int_eq(lst->count, 12);
+3 -3
View File
@@ -742,8 +742,8 @@ START_TEST(test_libipm_receive_unsupported_type)
*g_t_in->in_s->p = 'A'; /* unsupported type */ *g_t_in->in_s->p = 'A'; /* unsupported type */
c = libipm_msg_in_peek_type(g_t_in); c = libipm_msg_in_peek_type(g_t_in);
ck_assert_int_eq(c, '?'); /* peek should say this is an error */ ck_assert_int_eq(c, '?'); /* peek should say this is an error */
/* Parse it anyway */
status = libipm_msg_in_parse( g_t_in, "A", NULL); /* Parse it anyway */ status = libipm_msg_in_parse( g_t_in, "A", (const char *)0);
ck_assert_int_eq(status, E_LI_UNSUPPORTED_TYPE); ck_assert_int_eq(status, E_LI_UNSUPPORTED_TYPE);
} }
END_TEST END_TEST
@@ -783,7 +783,7 @@ START_TEST(test_libipm_receive_unimplemented_type)
*g_t_in->in_s->p = 'd'; /* reserved type */ *g_t_in->in_s->p = 'd'; /* reserved type */
c = libipm_msg_in_peek_type(g_t_in); c = libipm_msg_in_peek_type(g_t_in);
ck_assert_int_eq(c, 'd'); ck_assert_int_eq(c, 'd');
status = libipm_msg_in_parse( g_t_in, "d", NULL); status = libipm_msg_in_parse( g_t_in, "d", (const char *)0);
ck_assert_int_eq(status, E_LI_UNIMPLEMENTED_TYPE); ck_assert_int_eq(status, E_LI_UNIMPLEMENTED_TYPE);
} }
END_TEST END_TEST
+5 -3
View File
@@ -349,7 +349,8 @@ START_TEST(test_libipm_send_s_type)
ck_assert_int_eq(status, E_LI_SUCCESS); ck_assert_int_eq(status, E_LI_SUCCESS);
/* Check passing a NULL string doesn't crash the program */ /* Check passing a NULL string doesn't crash the program */
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "s", NULL); status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO,
"s", (const char *)0);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR); ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
} }
END_TEST END_TEST
@@ -409,7 +410,8 @@ START_TEST(test_libipm_send_B_type)
desc.data = NULL; desc.data = NULL;
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", &desc); status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", &desc);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR); ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", NULL); status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B",
(const struct libipm_fsb *)0);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR); ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
} }
END_TEST END_TEST
@@ -447,7 +449,7 @@ START_TEST(test_libipm_send_bad_types)
format[0] = c; format[0] = c;
status = libipm_msg_out_init(g_t_out, status = libipm_msg_out_init(g_t_out,
TEST_MESSAGE_NO_STRING_NO, TEST_MESSAGE_NO_STRING_NO,
format, NULL); format, (const char *)0);
if (status != expected_status) if (status != expected_status)
{ {
ck_abort_msg("Output char '%c'. Expected status %d, got %d", ck_abort_msg("Output char '%c'. Expected status %d, got %d",
+10 -9
View File
@@ -177,24 +177,25 @@ xrdp_process_params(int argc, char **argv,
value = ""; value = "";
} }
if (nocase_matches(option, "-help", "--help", "-h", NULL)) if (nocase_matches(option, "-help", "--help", "-h", (const char *)0))
{ {
startup_params->help = 1; startup_params->help = 1;
} }
else if (nocase_matches(option, "-kill", "--kill", "-k", NULL)) else if (nocase_matches(option, "-kill", "--kill", "-k",
(const char *)0))
{ {
startup_params->kill = 1; startup_params->kill = 1;
} }
else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n", else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n",
"-nd", "--nd", "-ns", "--ns", NULL)) "-nd", "--nd", "-ns", "--ns", (const char *)0))
{ {
startup_params->no_daemon = 1; startup_params->no_daemon = 1;
} }
else if (nocase_matches(option, "-v", "--version", NULL)) else if (nocase_matches(option, "-v", "--version", (const char *)0))
{ {
startup_params->version = 1; startup_params->version = 1;
} }
else if (nocase_matches(option, "-p", "--port", NULL)) else if (nocase_matches(option, "-p", "--port", (const char *)0))
{ {
index++; index++;
g_strncpy(startup_params->port, value, g_strncpy(startup_params->port, value,
@@ -211,20 +212,20 @@ xrdp_process_params(int argc, char **argv,
startup_params->port); startup_params->port);
} }
} }
else if (nocase_matches(option, "-f", "--fork", NULL)) else if (nocase_matches(option, "-f", "--fork", (const char *)0))
{ {
startup_params->fork = 1; startup_params->fork = 1;
g_writeln("--fork parameter found, ini override"); g_writeln("--fork parameter found, ini override");
} }
else if (nocase_matches(option, "--dump-config", NULL)) else if (nocase_matches(option, "--dump-config", (const char *)0))
{ {
startup_params->dump_config = 1; startup_params->dump_config = 1;
} }
else if (nocase_matches(option, "--license", NULL)) else if (nocase_matches(option, "--license", (const char *)0))
{ {
startup_params->license = 1; startup_params->license = 1;
} }
else if (nocase_matches(option, "-c", "--config", NULL)) else if (nocase_matches(option, "-c", "--config", (const char *)0))
{ {
index++; index++;
startup_params->xrdp_ini = value; startup_params->xrdp_ini = value;