net: turn name len check into an assert
PATCH 1/1 net: turn name len check into an assert
The new sanity check introduces a printf warning for some systems:
eth.c:233: warning: format '%zu' expects type 'size_t', but argument 3 has type 'int'
Rather than tweak the format string, use the new assert() helper instead.
--- net/eth.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
net/eth.c +1 -6
@@ -227,12 +227,7 @@ int eth_register(struct eth_device *dev) {struct eth_device *d; -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 );if (!eth_devices) { eth_current = eth_devices = dev;
Signature · 1 line
1.7.6
PATCH 1/1 net: turn name len check into an assert
Quoted 2 lines · Mike Frysinger
The new sanity check introduces a printf warning for some systems:
eth.c:233: warning: format '%zu' expects type 'size_t', but argument 3
has
Quoted 14 lines
type 'int'
Rather than tweak the format string, use the new
assert()helper instead.Signed-off-by Mike Frysinger <[email protected]>--- net/eth.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)net/eth.c +0
-0
net/eth.c int eth_register(struct eth_device *dev) · line 230
Quoted 10 lines
net/eth.c +1
-6@@ -227,12 +227,7 @@ int eth_register(struct eth_device *dev) {struct eth_device *d; -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 ?
Cheers
Quoted 3 lines
net/eth.c +0
-0if (!eth_devices) { eth_current = eth_devices = dev;
PATCH 1/1 net: turn name len check into an assert
Quoted 4 lines · On Monday, September 12, 2011 01:08:50 Marek Vasut wrote:
Quoted 3 lines · Mike Frysinger
net/eth.c +0
-0
Quoted 9 lines
net/eth.c int eth_register(struct eth_device *dev) · line 230
Quoted 7 lines
net/eth.c +1
-6-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)".
-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/7705650c/attachment.pgp
PATCH 1/1 net: turn name len check into an assert
Quoted 15 lines · Mike Frysinger
Quoted 4 lines · On Monday, September 12, 2011 01:08:50 Marek Vasut wrote:
Quoted 3 lines · Mike Frysinger
net/eth.c +0
-0Quoted 9 lines
net/eth.c int eth_register(struct eth_device *dev) · line 230
Quoted 7 lines
net/eth.c +1
-6-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 ?
Quoted 4 lines
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)".
-mike
The old code return -1, doesn't abort ;-)
PATCH 1/1 net: turn name len check into an assert
Quoted 9 lines · On Monday, September 12, 2011 13:06:13 Marek Vasut wrote:
Quoted 8 lines · Mike Frysinger
Quoted 7 lines · On Monday, September 12, 2011 01:08:50 Marek Vasut wrote:
net/eth.c int eth_register(struct eth_device *dev)
Quoted 6 lines · Mike Frysinger
net/eth.c +0
-3-size_t len =strlen (dev->name); -if (len >=NAMESIZE ) { - printf("Network driver name is too long (%zu >= %zu):
%s\n",
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
net/eth.c int eth_register(struct eth_device *dev) · line 230
Quoted 4 lines
net/eth.c +1
-3- len, NAMESIZE, dev->name); -return -1 ; - } +assert (strlen (dev->name) <NAMESIZE );Aren't you changing the logic here ?
Quoted 5 lines
Quoted 3 lines
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
Wolfgang Denk
AppliedPATCH 1/1 net: turn name len check into an assert
In reply to Mike FrysingerDear Mike Frysinger,
Quoted 9 lines · In message <[email protected]> you wrote:
The new sanity check introduces a printf warning for some systems:
eth.c:233: warning: format '%zu' expects type 'size_t', but argument 3 has type 'int'Rather than tweak the format string, use the new
assert()helper instead.Signed-off-by Mike Frysinger <[email protected]>--- net/eth.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 7 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "One day," said a dull voice from down below, "I'm going to be back in form again and you're going to be very sorry you said that. For a very long time. I might even go so far as to make even more Time just for you to be sorry in." - Terry Pratchett, _Small Gods_