* [U-Boot] [PATCH] net: turn name len check into an assert
@ 2011-09-12 4:49 Mike Frysinger
2011-09-12 5:08 ` Marek Vasut
2011-09-21 21:04 ` Wolfgang Denk
0 siblings, 2 replies; 6+ messages in thread
From: Mike Frysinger @ 2011-09-12 4:49 UTC (permalink / raw)
To: u-boot
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 <vapier@gentoo.org>
---
net/eth.c | 7 +------
1 files changed, 1 insertions(+), 6 deletions(-)
diff --git a/net/eth.c b/net/eth.c
index 5911b1c..02baa37 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -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;
--
1.7.6
^ permalink raw reply related [flat|nested] 6+ messages in thread* [U-Boot] [PATCH] net: turn name len check into an assert
2011-09-12 4:49 [U-Boot] [PATCH] net: turn name len check into an assert Mike Frysinger
@ 2011-09-12 5:08 ` Marek Vasut
2011-09-12 16:29 ` Mike Frysinger
2011-09-21 21:04 ` Wolfgang Denk
1 sibling, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2011-09-12 5:08 UTC (permalink / raw)
To: u-boot
On Monday, September 12, 2011 06:49:53 AM Mike Frysinger 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 <vapier@gentoo.org>
> ---
> net/eth.c | 7 +------
> 1 files changed, 1 insertions(+), 6 deletions(-)
>
> diff --git a/net/eth.c b/net/eth.c
> index 5911b1c..02baa37 100644
> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -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
>
> if (!eth_devices) {
> eth_current = eth_devices = dev;
^ permalink raw reply [flat|nested] 6+ messages in thread* [U-Boot] [PATCH] net: turn name len check into an assert
2011-09-12 5:08 ` Marek Vasut
@ 2011-09-12 16:29 ` Mike Frysinger
2011-09-12 17:06 ` Marek Vasut
0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2011-09-12 16:29 UTC (permalink / raw)
To: u-boot
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)".
-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
^ permalink raw reply [flat|nested] 6+ messages in thread* [U-Boot] [PATCH] net: turn name len check into an assert
2011-09-12 16:29 ` Mike Frysinger
@ 2011-09-12 17:06 ` Marek Vasut
2011-09-12 20:24 ` Mike Frysinger
0 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2011-09-12 17:06 UTC (permalink / raw)
To: u-boot
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)".
> -mike
The old code return -1, doesn't abort ;-)
^ permalink raw reply [flat|nested] 6+ messages in thread* [U-Boot] [PATCH] net: turn name len check into an assert
2011-09-12 17:06 ` Marek Vasut
@ 2011-09-12 20:24 ` Mike Frysinger
0 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2011-09-12 20:24 UTC (permalink / raw)
To: u-boot
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [U-Boot] [PATCH] net: turn name len check into an assert
2011-09-12 4:49 [U-Boot] [PATCH] net: turn name len check into an assert Mike Frysinger
2011-09-12 5:08 ` Marek Vasut
@ 2011-09-21 21:04 ` Wolfgang Denk
1 sibling, 0 replies; 6+ messages in thread
From: Wolfgang Denk @ 2011-09-21 21:04 UTC (permalink / raw)
To: u-boot
Dear Mike Frysinger,
In message <1315802993-12798-1-git-send-email-vapier@gentoo.org> 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 <vapier@gentoo.org>
> ---
> net/eth.c | 7 +------
> 1 files changed, 1 insertions(+), 6 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
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_
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-09-21 21:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-12 4:49 [U-Boot] [PATCH] net: turn name len check into an assert Mike Frysinger
2011-09-12 5:08 ` Marek Vasut
2011-09-12 16:29 ` Mike Frysinger
2011-09-12 17:06 ` Marek Vasut
2011-09-12 20:24 ` Mike Frysinger
2011-09-21 21:04 ` Wolfgang Denk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox