From 5ad7308d7bfce8e091b6d1427d6899e21403526d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20F=2E=20Aasen?= Date: Wed, 27 Dec 2023 17:25:19 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Fixes=20compiler=20warning:=20comparison=20?= =?UTF-8?q?will=20always=20evaluate=20as=20=E2=80=98true=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is backported from master by commit from Petter Reinholdtsen, commit 99d4638e2c787c9c2122232090ca7a7ea5c0dae4 --- src/hal/classicladder/emc_mods.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hal/classicladder/emc_mods.c b/src/hal/classicladder/emc_mods.c index 83cc9275e71..d9ab3d393ff 100644 --- a/src/hal/classicladder/emc_mods.c +++ b/src/hal/classicladder/emc_mods.c @@ -134,7 +134,7 @@ char * ConvVarNameToHalSigName( char * VarNameParam ) hal_pin_t *pin = halpr_find_pin_by_name(pin_name); if(pin && pin->signal) { hal_sig_t *sig = SHMPTR(pin->signal); - if(sig->name) { + if(0 != sig->name[0]) { static char sig_name[100]; // char *arrow = "\xe2\x86\x90"; char *arrow = "\xe2\x87\x92"; From 8d9c5aa359aa7094d0b431f1fb2d84856d6fdb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20F=2E=20Aasen?= Date: Wed, 27 Dec 2023 17:27:48 +0100 Subject: [PATCH 2/3] Fixes warning about address will never be NULL The variable is an array, so it can't be NULL. --- src/libnml/rcs/rcs_print.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libnml/rcs/rcs_print.cc b/src/libnml/rcs/rcs_print.cc index 3eca2c001f8..d96c80c74f6 100644 --- a/src/libnml/rcs/rcs_print.cc +++ b/src/libnml/rcs/rcs_print.cc @@ -369,9 +369,6 @@ int rcs_fputs(const char *_str) break; case RCS_PRINT_TO_FILE: if (NULL == rcs_print_file_stream) { - if (NULL == rcs_print_file_name) { - return EOF; - } rcs_print_file_stream = fopen(rcs_print_file_name, "a+"); } if (NULL == rcs_print_file_stream) { From c715355018c42414b6ca25eed693a6f17074dc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20F=2E=20Aasen?= Date: Wed, 27 Dec 2023 17:31:55 +0100 Subject: [PATCH 3/3] Fixes another address that can't be NULL The variable 'ProcessName' is an array of 'char', it can't be NULL, so don't check for it. Make sure that the variable 'proc_name' is initialized to NULL. Change how we copy the string from malloc() and strcpy() to strndup(). As with malloc() we don't check the result, this is done before usage. --- src/libnml/nml/nml_mod.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libnml/nml/nml_mod.cc b/src/libnml/nml/nml_mod.cc index 2f6ef3e71d1..4ea8316f385 100644 --- a/src/libnml/nml/nml_mod.cc +++ b/src/libnml/nml/nml_mod.cc @@ -163,6 +163,7 @@ NML_MODULE::zero_common_vars () min_run_time = 1e6; max_run_time = 0; start_cycle_time = 0; + proc_name = 0; temp_file = 0; temp_line = 0; Dclock_expiration = 0; @@ -271,12 +272,7 @@ NML_MODULE::setCmdChannel (RCS_CMD_CHANNEL * cmd_channel) } if (NULL != commandIn->cms) { - if (NULL != commandIn->cms->ProcessName) - { - proc_name = - (char *) malloc (strlen (commandIn->cms->ProcessName) + 1); - strcpy (proc_name, commandIn->cms->ProcessName); - } + proc_name = strndup(commandIn->cms->ProcessName, LINELEN); } }