Add a macro that, for a given count of keys, returns the total size of
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 17 Feb 2013 03:45:06 +0000 (03:45 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 17 Feb 2013 03:45:06 +0000 (03:45 +0000)
an AirpcapKeysCollection structure with that number of keys, and use it
instead of doing the calculation manually.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@47699 f5534014-38df-0310-8fa8-9805f1628bb7

airpcap.h
airpcap_loader.c
ui/gtk/airpcap_gui_utils.c

index 8813ed0e13e701917617a7521d246eafd5992097..dd245451dce0cc147e8fbe0b66767525b7fe412d 100644 (file)
--- a/airpcap.h
+++ b/airpcap.h
@@ -169,13 +169,13 @@ AirpcapMacAddress, *PAirpcapMacAddress;
 /*!
   \brief This structure is used to store a collection of WEP keys.
   Note that the definition of the structure doesn't contain any key, so be careful to allocate a buffer
-  with the size of the key, like in the following example:
+  with the size of the set of keys, as per the following example:
 
   \code
     PAirpcapKeysCollection KeysCollection;
     guint KeysCollectionSize;
 
-    KeysCollectionSize = sizeof(AirpcapKeysCollection) + NumKeys * sizeof(AirpcapKey);
+    KeysCollectionSize = AirpcapKeysCollectionSize(NumKeys);
 
     KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
     if(!KeysCollection)
@@ -190,6 +190,8 @@ typedef struct _AirpcapKeysCollection
     AirpcapKey Keys[0];             /* < Array of nKeys keys. */
 } AirpcapKeysCollection, *PAirpcapKeysCollection;
 
+#define AirpcapKeysCollectionSize(nKeys) (sizeof(AirpcapKeysCollection) + ((nKeys) * sizeof(AirpcapKey)))
+
 /*!
   \brief Packet header.
 
index 3b745823c252a82226f069451953d641ff0952cd..fca1d3179d0e905c699a678d49eb4b049be7dad5 100644 (file)
@@ -350,7 +350,7 @@ write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
     /*
      * Calculate the size of the keys collection
      */
-    KeysCollectionSize = (guint)(sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey));
+    KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
 
     /*
      * Allocate the collection
@@ -449,7 +449,7 @@ write_wlan_driver_wep_keys_to_registry(GList* key_list)
     /*
      * Calculate the size of the keys collection
      */
-    KeysCollectionSize = (guint)(sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey));
+    KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
 
     /*
      * Allocate the collection
index c33308cde5b386512fb30022fce3fd4c1350482e..fec1ad35947d91606f0498f135fe1041d0bb5f68 100644 (file)
@@ -715,7 +715,7 @@ airpcap_add_keys_to_driver_from_list(GtkListStore *key_list_store, airpcap_if_in
     /*
      * Calculate the size of the keys collection
      */
-    KeysCollectionSize = (guint) (sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey));
+    KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
 
     /*
      * Allocate the collection