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;
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))
{
+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
* @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
* 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
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,
xserver, screen,
"-auth", authfile,
NULL);
LIST_ADD_STRDUP_TERM);
/* additional parameters from sesman.ini file */
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,
"-geometry", geometry,
"-depth", depth,
NULL);
LIST_ADD_STRDUP_TERM);
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);
list_add_strdup_multi(params,
"-rfbauth", passwd_file,
NULL);
LIST_ADD_STRDUP_TERM);
}
else if (port != NULL)
{
@@ -478,7 +478,7 @@ prepare_xvnc_xserver_params(const struct session_parameters *s,
"-rfbunixpath", port,
"-rfbunixmode", sock_mode,
"-SecurityTypes", "None",
NULL);
LIST_ADD_STRDUP_TERM);
}
/* additional parameters from sesman.ini file */
+2 -1
View File
@@ -67,7 +67,8 @@ make_xwait_command(int display)
cmd->auto_free = 1;
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);
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 (!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;
}
+8 -7
View File
@@ -152,32 +152,33 @@ sesman_process_params(int argc, char **argv,
value = "";
}
if (nocase_matches(option, "-help", "--help", "-h", NULL))
if (nocase_matches(option, "-help", "--help", "-h", (const char *)0))
{
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;
}
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;
}
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;
}
else if (nocase_matches(option, "-v", "--version", NULL))
else if (nocase_matches(option, "-v", "--version", (const char *)0))
{
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;
}
else if (nocase_matches(option, "-c", "--config", NULL))
else if (nocase_matches(option, "-c", "--config", (const char *)0))
{
index++;
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,
"0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "10", "11",
NULL);
LIST_ADD_STRDUP_TERM);
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 */
c = libipm_msg_in_peek_type(g_t_in);
ck_assert_int_eq(c, '?'); /* peek should say this is an error */
status = libipm_msg_in_parse( g_t_in, "A", NULL); /* Parse it anyway */
/* Parse it anyway */
status = libipm_msg_in_parse( g_t_in, "A", (const char *)0);
ck_assert_int_eq(status, E_LI_UNSUPPORTED_TYPE);
}
END_TEST
@@ -783,7 +783,7 @@ START_TEST(test_libipm_receive_unimplemented_type)
*g_t_in->in_s->p = 'd'; /* reserved type */
c = libipm_msg_in_peek_type(g_t_in);
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);
}
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);
/* 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);
}
END_TEST
@@ -409,7 +410,8 @@ START_TEST(test_libipm_send_B_type)
desc.data = NULL;
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", &desc);
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);
}
END_TEST
@@ -447,7 +449,7 @@ START_TEST(test_libipm_send_bad_types)
format[0] = c;
status = libipm_msg_out_init(g_t_out,
TEST_MESSAGE_NO_STRING_NO,
format, NULL);
format, (const char *)0);
if (status != expected_status)
{
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 = "";
}
if (nocase_matches(option, "-help", "--help", "-h", NULL))
if (nocase_matches(option, "-help", "--help", "-h", (const char *)0))
{
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;
}
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;
}
else if (nocase_matches(option, "-v", "--version", NULL))
else if (nocase_matches(option, "-v", "--version", (const char *)0))
{
startup_params->version = 1;
}
else if (nocase_matches(option, "-p", "--port", NULL))
else if (nocase_matches(option, "-p", "--port", (const char *)0))
{
index++;
g_strncpy(startup_params->port, value,
@@ -211,20 +212,20 @@ xrdp_process_params(int argc, char **argv,
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;
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;
}
else if (nocase_matches(option, "--license", NULL))
else if (nocase_matches(option, "--license", (const char *)0))
{
startup_params->license = 1;
}
else if (nocase_matches(option, "-c", "--config", NULL))
else if (nocase_matches(option, "-c", "--config", (const char *)0))
{
index++;
startup_params->xrdp_ini = value;