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

Re: [Minios-devel] [UNIKRAFT/LWIP PATCH] Fix compilation warning about comparison between signed and unsigned integer


  • To: Julien Grall <Julien.Grall@xxxxxxx>, "minios-devel@xxxxxxxxxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxxxxxxxxx>, Simon Kuenzer <simon.kuenzer@xxxxxxxxx>, Costin Lupu <costin.lupu@xxxxxxxxx>
  • From: "Justin He (Arm Technology China)" <Justin.He@xxxxxxx>
  • Date: Fri, 11 Oct 2019 13:44:29 +0000
  • Accept-language: en-US, zh-CN
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BOdvaPHP9AFvQ+HirddAftZDg2qQJqMz+e9GXA8tNmI=; b=iuDH35T5VQX2abkanZDj+ELMmKrSHZHH7EV4Qu8z5bE3ilTTkMW/cPc2egwYIq1t03N8p5z9Sbm9kRSNzCgJEMmEofPlIfwZbrO8GEO93phzdoSi2/vmlCl6EZVTRf5cPGZ+swXvGs0eOU0TxECmHM/SpHGnFxvVFxrAM9L620TpfE5H1/a8JP94YTLI6ombaJGxdRPqwFySoV9pcPNDv0rw5wXZW4hq1X8wlPNzdpHj7wJu0mrayFM9/OEM2YZEn8lCVB8RYJzs+zTaZwcS87NU2Xi+j08Lyu5u1V80dlATd4iFiLu/3umXQgcx2dCznQGL3uhazTqPaASFTO+xeQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=axHGdev0ShXaAVro7eIVde9uwDTCFxRFeGqNx+ouou0Yv+EVxOwEpi7D8sO/TGpQIo7HWebt7w2kfbusFXbaj2yZkuuhVloxvIAKitWzIkoFaoGq/L3lkctdVUsFfI2CZUT44dI07bhadj1I3Y13FrS3i4h1vQMkK70OkyZe3a0d5yaTvBEwDhtXKtSxcfCMulgHMdj5EA1gA4/K7mKEZR6O1S5SK8UCyXQwlF926vxYV5Z2Wes08Z99RK2lKhp8IifqpgoVyi6yvoL10PobGKQRsc1JhPqcf+LdLyuLsaQyJbNKGGq7rilxRlB1BH2dvxwdhAdcAaXUS3OGsQK0KQ==
  • Authentication-results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.xenproject.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.xenproject.org; dmarc=none action=none header.from=arm.com;
  • Authentication-results-original: spf=none (sender IP is ) smtp.mailfrom=Justin.He@xxxxxxx;
  • Cc: Felipe Huici <felipe.huici@xxxxxxxxx>, "Kaly Xin \(Arm Technology China\)" <Kaly.Xin@xxxxxxx>, nd <nd@xxxxxxx>, "Sharan.Santhanam@xxxxxxxxx" <Sharan.Santhanam@xxxxxxxxx>, "Santiago.Pagani@xxxxxxxxx" <Santiago.Pagani@xxxxxxxxx>
  • Delivery-date: Fri, 11 Oct 2019 13:44:52 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Nodisclaimer: True
  • Original-authentication-results: spf=none (sender IP is ) smtp.mailfrom=Justin.He@xxxxxxx;
  • Thread-index: AQHVgBY4RwpxttLkMky7kpo3VpJzGqdVc4zA
  • Thread-topic: [UNIKRAFT/LWIP PATCH] Fix compilation warning about comparison between signed and unsigned integer

Hi Julien

> -----Original Message-----
> From: Julien Grall <julien.grall@xxxxxxx>
> Sent: Friday, October 11, 2019 5:28 PM
> To: Justin He (Arm Technology China) <Justin.He@xxxxxxx>; minios-
> devel@xxxxxxxxxxxxxxxxxxxx; Simon Kuenzer <simon.kuenzer@xxxxxxxxx>;
> Costin Lupu <costin.lupu@xxxxxxxxx>
> Cc: Sharan.Santhanam@xxxxxxxxx; Felipe Huici <felipe.huici@xxxxxxxxx>;
> Kaly Xin (Arm Technology China) <Kaly.Xin@xxxxxxx>;
> Santiago.Pagani@xxxxxxxxx; nd <nd@xxxxxxx>
> Subject: Re: [UNIKRAFT/LWIP PATCH] Fix compilation warning about
> comparison between signed and unsigned integer
> 
> Hi,
> 
> On 11/10/2019 09:55, Jia He wrote:
> > Without this patch, compiler(gcc version 7.4.0) reports:
> > proto.c: In function ‘getprotoent’:
> > proto.c:85:10: warning: comparison between signed and unsigned integer
> > expressions [-Wsign-compare]
> >    if (idx >= sizeof(protos))
> >            ^~
> >
> > Signed-off-by: Jia He <justin.he@xxxxxxx>
> > ---
> >   proto.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/proto.c b/proto.c
> > index 517f258..7d32bc6 100644
> > --- a/proto.c
> > +++ b/proto.c
> > @@ -82,7 +82,7 @@ struct protoent *getprotoent(void)
> >     static struct protoent p;
> >     static const char *aliases;
> >
> > -   if (idx >= sizeof(protos))
> > +   if ((unsigned int)idx >= sizeof(protos))
> 
> I am always cautious when I see an explicit cast.
> 
> If 'idx' is signed then it may mean it can be negative. Both the implicit and
> explicit cast version will pass the check for negative value. But, IMHO, this 
> is
> a bad side-effect.
> 
> Looking at the code, I can't see a good reason for 'idx' to be signed. So why
> not switch to size_t?
> 
> I suggested size_t and not unsigned int because you increment it by strlen(..)
> which return a size_t.

Okay, it is reasonable.
Thanks


--
Cheers,
Justin (Jia He)


> 
> >             return NULL;
> >     p.p_proto = protos[idx];
> >     p.p_name = (char *)&protos[idx+1];
> >
> 
> Cheers,
> 
> --
> Julien Grall
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.