[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/3] Fix compile-time warnings.

From: Kamil Dudka
Subject: Re: [PATCH 3/3] Fix compile-time warnings.
Date: Mon, 4 Feb 2013 14:00:28 +0100
User-agent: KMail/1.12.4 (Linux/2.6.32-355.el6.x86_64; KDE/4.3.4; x86_64; ; )

On Sunday 03 February 2013 23:07:42 Kamil Dudka wrote:
> diff --git a/find/exec.c b/find/exec.c
> index aa69fe3..f731d82 100644
> --- a/find/exec.c
> +++ b/find/exec.c
> @@ -324,7 +324,7 @@ launch (struct buildcmd_control *ctl, void
>  *usercontext, int argc, char **argv) }
>       }
> -      if (bc_args_exceed_testing_limit (argv))
> +      if (bc_args_exceed_testing_limit ((const char **) argv))
>       errno = E2BIG;
>        else
>       execvp (argv[0], argv);

As James pointed out, the above type-cast is insane because it might allow to 
assign a string literal to an item of an array of modifiable strings.  If we 
want the compiler to check that bc_args_exceed_testing_limit() accesses the 
array of strings in a read-only manner, its prototype should be:

bool bc_args_exceed_testing_limit (const char *const *argv);

The problem is that such a type definition is actually useful in C++ only.
For C compilers, we would need the explicit type-casts anyway.  Hence, I 
propose to remove the const modifier from the bc_args_exceed_testing_limit() 
prototype completely because the C language does not seem to support the
type-constraint we need.  Here are some resources on this topic:



Does anyone have a better idea how to fix these warnings?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]