[U-Boot] [PATCH] net: turn name len check into an assert

Mike Frysinger vapier at gentoo.org
Mon Sep 12 22:24:03 CEST 2011


On Monday, September 12, 2011 13:06:13 Marek Vasut wrote:
> On Monday, September 12, 2011 06:29:10 PM Mike Frysinger wrote:
> > On Monday, September 12, 2011 01:08:50 Marek Vasut wrote:
> > > On Monday, September 12, 2011 06:49:53 AM Mike Frysinger wrote:
> > > > --- a/net/eth.c
> > > > +++ b/net/eth.c
> > > > 
> > > > -	size_t len = strlen(dev->name);
> > > > -	if (len >= NAMESIZE) {
> > > > -		printf("Network driver name is too long (%zu >= %zu): 
%s\n",
> > > > -						len, NAMESIZE, dev->name);
> > > > -		return -1;
> > > > -	}
> > > > +	assert(strlen(dev->name) < NAMESIZE);
> > > 
> > > Aren't you changing the logic here ?
> > 
> > pretty sure it's the same.  old code would warn when "len >= max", while
> > mine asserts that "len < max" and thus aborts when "!(len < max)" and
> > based on boolean logic, "(x >= y) == !(x < y)".
> 
> The old code return -1, doesn't abort ;-)

yes, but the old code only executes when there's an error you need to fix.  
aborting is fine.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110912/1b71f28e/attachment.pgp 


More information about the U-Boot mailing list