bug-hurd
[Top][All Lists]
Advanced

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

[PATCH] Assert the device name before storing it.


From: Sergiu Ivanov
Subject: [PATCH] Assert the device name before storing it.
Date: Wed, 30 Dec 2009 17:49:45 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

* eth-multiplexer/vdev.c (add_vdev): Assert the name of the
device to be created before copying it into the vdev
structure.
---

Hello,

On Sat, Dec 26, 2009 at 06:03:46PM +0100, olafBuddenhagen@gmx.net wrote:
> Hi,
> 
> On Thu, Dec 24, 2009 at 10:25:47PM +0200, Sergiu Ivanov wrote:
> 
> > Still, I somehow feel bad about copying from a pointer without doing
> > an extra check.  Would it be an acceptable idea to assert (name) ?
> 
> Sure: if you think that something *should* be a certain way (non-NULL in
> this case), but want to protect against the possibility that the
> assumption was wrong after all, because of something that was overlooked
> -- that's precisely what assert() is for :-)

Great :-) This patch adds this assert.

Regards,
Sergiu

---
 eth-multiplexer/vdev.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/eth-multiplexer/vdev.c b/eth-multiplexer/vdev.c
index dac9802..7e2a40b 100644
--- a/eth-multiplexer/vdev.c
+++ b/eth-multiplexer/vdev.c
@@ -27,6 +27,7 @@
 #include <arpa/inet.h>
 #include <stdlib.h>
 #include <error.h>
+#include <assert.h>
 
 #include <cthreads.h>
 
@@ -135,6 +136,7 @@ add_vdev (char *name, int size,
 
   vdev->dev_port = ports_get_right (vdev);
   ports_port_deref (vdev);
+  assert (name);
   strncpy (vdev->name, name, IFNAMSIZ);
   vdev->if_header_size = ETH_HLEN;
   vdev->if_mtu = ETH_MTU;
-- 
1.5.2.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]