From 9d796fb31fca243198e3f194e48b8efcf624e19b Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 28 Feb 2025 16:10:35 +0100 Subject: [PATCH] getopt_long() returns int Use the right type for variable, as getopt_long() returns an int. Using char is not a problem on x86, but prevents the return of -1 in case of parameter reading end. This led to infinite loops on ARM, which is fixed through the variable type change. An additional counter measure (showing the problem) would be to print and error out when reading an undefined parameter, which is added here as well. This has been forgotten when making the same change for getopt() in cf9854601cce ("getopt() returns int"). --- openair3/NAS/TOOLS/nvram.c | 4 +++- openair3/NAS/TOOLS/usim.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/openair3/NAS/TOOLS/nvram.c b/openair3/NAS/TOOLS/nvram.c index 80d8b34893..ad39462dc9 100644 --- a/openair3/NAS/TOOLS/nvram.c +++ b/openair3/NAS/TOOLS/nvram.c @@ -69,7 +69,7 @@ int main (int argc, char * const argv[]) {NULL, 0, NULL, 0} }; int option_index; - char option_short; + int option_short; /* * Read command line parameters @@ -94,6 +94,8 @@ int main (int argc, char * const argv[]) output_dir = optarg; break; default: + fprintf(stderr, "unknown option %d, exit\n", option_short); + exit(1); break; } } diff --git a/openair3/NAS/TOOLS/usim.c b/openair3/NAS/TOOLS/usim.c index 84b4cfbdf8..9d74499144 100644 --- a/openair3/NAS/TOOLS/usim.c +++ b/openair3/NAS/TOOLS/usim.c @@ -69,7 +69,7 @@ int main (int argc, char * const argv[]) {NULL, 0, NULL, 0} }; int option_index; - char option_short; + int option_short; /* * Read command line parameters @@ -94,6 +94,8 @@ int main (int argc, char * const argv[]) output_dir = optarg; break; default: + fprintf(stderr, "unknown option %d, exit\n", option_short); + exit(1); break; } }