diff mbox series

fwts_args: constify fields in struct fwts_option

Message ID 20210410220544.1031969-1-colin.king@canonical.com
State Accepted
Headers show
Series fwts_args: constify fields in struct fwts_option | expand

Commit Message

Colin Ian King April 10, 2021, 10:05 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The fields are not meant to be modified so constify them.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/include/fwts_args.h | 8 ++++----
 src/lib/src/fwts_args.c     | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Alex Hung April 11, 2021, 8:51 p.m. UTC | #1
On 2021-04-10 4:05 p.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The fields are not meant to be modified so constify them.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_args.h | 8 ++++----
>  src/lib/src/fwts_args.c     | 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/lib/include/fwts_args.h b/src/lib/include/fwts_args.h
> index 9cab3d7f..8d085e36 100644
> --- a/src/lib/include/fwts_args.h
> +++ b/src/lib/include/fwts_args.h
> @@ -26,10 +26,10 @@
>  #include <getopt.h>
>  
>  typedef struct {
> -	char		*long_name;	/* e.g. "quiet", long name */
> -	char		*short_name;	/* e.g. "q", short help info */
> -	int		has_arg;
> -	char		*explanation;	/* explanation: "Enabled quiet mode..." */
> +	const char *long_name;		/* e.g. "quiet", long name */
> +	const char *short_name;		/* e.g. "q", short help info */
> +	const int  has_arg;
> +	const char *explanation;	/* explanation: "Enabled quiet mode..." */
>  } fwts_option;
>  
>  #include "fwts.h"
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index a4af2f5d..4df36334 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -125,7 +125,7 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>  		options_table = fwts_list_data(fwts_options_table *, item);
>  
>  		for (i = 0; i < options_table->num_options; i++, n++) {
> -			char *short_name = options_table->options[i].short_name;
> +			const char *short_name = options_table->options[i].short_name;
>  			size_t len;
>  
>  			long_options[n].name    = options_table->options[i].long_name;
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu April 12, 2021, 6:53 a.m. UTC | #2
On 4/11/21 6:05 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The fields are not meant to be modified so constify them.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_args.h | 8 ++++----
>  src/lib/src/fwts_args.c     | 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/lib/include/fwts_args.h b/src/lib/include/fwts_args.h
> index 9cab3d7f..8d085e36 100644
> --- a/src/lib/include/fwts_args.h
> +++ b/src/lib/include/fwts_args.h
> @@ -26,10 +26,10 @@
>  #include <getopt.h>
>  
>  typedef struct {
> -	char		*long_name;	/* e.g. "quiet", long name */
> -	char		*short_name;	/* e.g. "q", short help info */
> -	int		has_arg;
> -	char		*explanation;	/* explanation: "Enabled quiet mode..." */
> +	const char *long_name;		/* e.g. "quiet", long name */
> +	const char *short_name;		/* e.g. "q", short help info */
> +	const int  has_arg;
> +	const char *explanation;	/* explanation: "Enabled quiet mode..." */
>  } fwts_option;
>  
>  #include "fwts.h"
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index a4af2f5d..4df36334 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -125,7 +125,7 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>  		options_table = fwts_list_data(fwts_options_table *, item);
>  
>  		for (i = 0; i < options_table->num_options; i++, n++) {
> -			char *short_name = options_table->options[i].short_name;
> +			const char *short_name = options_table->options[i].short_name;
>  			size_t len;
>  
>  			long_options[n].name    = options_table->options[i].long_name;
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/include/fwts_args.h b/src/lib/include/fwts_args.h
index 9cab3d7f..8d085e36 100644
--- a/src/lib/include/fwts_args.h
+++ b/src/lib/include/fwts_args.h
@@ -26,10 +26,10 @@ 
 #include <getopt.h>
 
 typedef struct {
-	char		*long_name;	/* e.g. "quiet", long name */
-	char		*short_name;	/* e.g. "q", short help info */
-	int		has_arg;
-	char		*explanation;	/* explanation: "Enabled quiet mode..." */
+	const char *long_name;		/* e.g. "quiet", long name */
+	const char *short_name;		/* e.g. "q", short help info */
+	const int  has_arg;
+	const char *explanation;	/* explanation: "Enabled quiet mode..." */
 } fwts_option;
 
 #include "fwts.h"
diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
index a4af2f5d..4df36334 100644
--- a/src/lib/src/fwts_args.c
+++ b/src/lib/src/fwts_args.c
@@ -125,7 +125,7 @@  int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
 		options_table = fwts_list_data(fwts_options_table *, item);
 
 		for (i = 0; i < options_table->num_options; i++, n++) {
-			char *short_name = options_table->options[i].short_name;
+			const char *short_name = options_table->options[i].short_name;
 			size_t len;
 
 			long_options[n].name    = options_table->options[i].long_name;