diff mbox

Net: rxrpc: signed and unsigned issue, need type cast for n_elem.

Message ID 51750FC0.8000603@asianux.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Chen Gang April 22, 2013, 10:24 a.m. UTC
n_elem is unsigned int which never < 0.
  but it seems, we realy need check it whether < 0.
  so need a type cast for it.

  find it by EXTRA_CFLAGS=-W


Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 net/rxrpc/ar-key.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Ben Hutchings April 22, 2013, 7:34 p.m. UTC | #1
On Mon, 2013-04-22 at 18:24 +0800, Chen Gang wrote:
> n_elem is unsigned int which never < 0.
>   but it seems, we realy need check it whether < 0.
>   so need a type cast for it.
> 
>   find it by EXTRA_CFLAGS=-W
> 
> 
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
>  net/rxrpc/ar-key.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
> index 7633a75..ba0b722 100644
> --- a/net/rxrpc/ar-key.c
> +++ b/net/rxrpc/ar-key.c
> @@ -346,7 +346,7 @@ static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td,
>  
>  	n_elem = ntohl(*xdr++);
>  	toklen -= 4;
> -	if (n_elem < 0 || n_elem > max_n_elem)
> +	if ((int)n_elem < 0 || n_elem > max_n_elem)

(int)n_elem < 0 is equivalent to n_elem >= 0x80000000, and if that is
true then n_elem > max_n_elem (because max_n_elem <= 0xff).

Ben.

>  		return -EINVAL;
>  	*_n_elem = n_elem;
>  	if (n_elem > 0) {
diff mbox

Patch

diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
index 7633a75..ba0b722 100644
--- a/net/rxrpc/ar-key.c
+++ b/net/rxrpc/ar-key.c
@@ -346,7 +346,7 @@  static int rxrpc_krb5_decode_tagged_array(struct krb5_tagged_data **_td,
 
 	n_elem = ntohl(*xdr++);
 	toklen -= 4;
-	if (n_elem < 0 || n_elem > max_n_elem)
+	if ((int)n_elem < 0 || n_elem > max_n_elem)
 		return -EINVAL;
 	*_n_elem = n_elem;
 	if (n_elem > 0) {