diff mbox

[3/8] policycoreutils/semodule: hide -Wwrite-strings warnings

Message ID 70479ea3-a2c0-56d8-34f2-e9f25c814753@tycho.nsa.gov (mailing list archive)
State Not Applicable
Headers show

Commit Message

James Carter Feb. 6, 2017, 3:57 p.m. UTC
On 02/05/2017 10:58 AM, Nicolas Iooss wrote:
> When building with "clang -Wwrite-strings", the compiler complains about
> initializing a char* array (variable genhomedirconargv) with literal
> strings (which are in read-only memory).
>
> However the programs needs to use a non-const char* array in order to
> fake arguments of getopt_long() (called by parse_command_line()). Silent
> the compiler warnings by introducing casts to char*.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
>  policycoreutils/semodule/semodule.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
> index ce048bc061b9..36686d0230a8 100644
> --- a/policycoreutils/semodule/semodule.c
> +++ b/policycoreutils/semodule/semodule.c
> @@ -341,7 +341,7 @@ int main(int argc, char *argv[])
>  	int i, commit = 0;
>  	int result;
>  	int status = EXIT_FAILURE;
> -	char *genhomedirconargv[] = { "genhomedircon", "-B", "-n" };
> +	char *genhomedirconargv[] = { (char *)"genhomedircon", (char *)"-B", (char *)"-n" };
>  	create_signal_handlers();
>  	if (strcmp(basename(argv[0]), "genhomedircon") == 0) {
>  		argc = 3;
>

I think that I would prefer the following for this one:
diff mbox

Patch

diff --git a/policycoreutils/semodule/semodule.c 
b/policycoreutils/semodule/semodule.c
index ce048bc..c63a864 100644
--- a/policycoreutils/semodule/semodule.c
+++ b/policycoreutils/semodule/semodule.c
@@ -341,11 +341,11 @@  int main(int argc, char *argv[])
  	int i, commit = 0;
  	int result;
  	int status = EXIT_FAILURE;
-	char *genhomedirconargv[] = { "genhomedircon", "-B", "-n" };
+	const char *genhomedirconargv[] = { "genhomedircon", "-B", "-n" };
  	create_signal_handlers();
  	if (strcmp(basename(argv[0]), "genhomedircon") == 0) {
  		argc = 3;
-		argv=genhomedirconargv;
+		argv = (char **)genhomedirconargv;
  	}
  	parse_command_line(argc, argv);