aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ipv4.c
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>2006-03-08 13:36:40 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>2006-03-08 13:36:40 +0000
commitae1041e0817f7b6b4788c743106684d5f0426c61 (patch)
tree36eee350b8aef1564d1b7554adbdcf8e6ac83785 /epan/ipv4.c
parent3cd2777adc40977665328c1367775738da8b69ac (diff)
Coverity CID 103 pointed me to this section of code. The buffer
overrun that Coverity thought existed does not exist. But I did notice something else: a signed/unsigned disparity between net_bits and new_nmask_bits. So I fixed that, then realized that the function in question, a static function named created_mask, is only used by one other function in the file. So I got ride of create_nmask and moved its logic into the single calling function, ipv4_addr_set_netmask_bits. svn path=/trunk/; revision=17529
Diffstat (limited to 'epan/ipv4.c')
-rw-r--r--epan/ipv4.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/epan/ipv4.c b/epan/ipv4.c
index 7dfae9761b..622d1e209b 100644
--- a/epan/ipv4.c
+++ b/epan/ipv4.c
@@ -36,7 +36,6 @@
#include "ipv4.h"
#include "packet.h" /* for ip_to_str */
-static guint32 create_nmask(gint net_bits);
ipv4_addr*
ipv4_addr_new(void)
@@ -69,8 +68,21 @@ ipv4_addr_set_net_order_addr(ipv4_addr *ipv4, guint32 new_addr)
void
ipv4_addr_set_netmask_bits(ipv4_addr *ipv4, guint new_nmask_bits)
{
-/* ipv4->nmask_bits = new_nmask_bits;*/
- ipv4->nmask = create_nmask(new_nmask_bits);
+ static guint32 bitmasks[33] = {
+ 0x00000000,
+ 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000,
+ 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
+ 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
+ 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000,
+ 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000,
+ 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00,
+ 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0,
+ 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff,
+ };
+
+ g_assert(new_nmask_bits <= 32);
+
+ ipv4->nmask = bitmasks[new_nmask_bits];
}
guint32
@@ -92,26 +104,6 @@ ipv4_addr_str_buf(const ipv4_addr *ipv4, gchar *buf)
ip_to_str_buf((guint8*)&ipv4_host_order, buf);
}
-static guint32
-create_nmask(gint net_bits)
-{
- static guint32 bitmasks[33] = {
- 0x00000000,
- 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000,
- 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
- 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
- 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000,
- 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000,
- 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00,
- 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0,
- 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff,
- };
-
- g_assert(net_bits <= 32);
-
- return bitmasks[net_bits];
-}
-
/*