[openib-general] [PATCH] OpenSM/st.c: Fix some size_t issues related to memory allocation in st.c

Hal Rosenstock halr at voltaire.com
Fri Feb 17 09:27:37 PST 2006


OpenSM/st.c: Fix some size_t issues related to memory allocation in st.c

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

Index: include/opensm/st.h
===================================================================
--- include/opensm/st.h	(revision 5436)
+++ include/opensm/st.h	(working copy)
@@ -40,6 +40,8 @@
 #ifndef ST_INCLUDED
 #define ST_INCLUDED
 
+#include <stdlib.h>
+
 #ifdef __cplusplus
 #  define BEGIN_C_DECLS extern "C" {
 #  define END_C_DECLS   }
@@ -79,11 +81,11 @@ struct st_table {
 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};
 
 st_table *st_init_table(struct st_hash_type *);
-st_table *st_init_table_with_size(struct st_hash_type *, int);
+st_table *st_init_table_with_size(struct st_hash_type *, size_t);
 st_table *st_init_numtable(void);
-st_table *st_init_numtable_with_size(int);
+st_table *st_init_numtable_with_size(size_t);
 st_table *st_init_strtable(void);
-st_table *st_init_strtable_with_size(int);
+st_table *st_init_strtable_with_size(size_t);
 int st_delete(st_table *, st_data_t *, st_data_t *);
 int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
 int st_insert(st_table *, st_data_t, st_data_t);
Index: opensm/st.c
===================================================================
--- opensm/st.c	(revision 5436)
+++ opensm/st.c	(working copy)
@@ -42,7 +42,6 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <opensm/st.h>
 
@@ -102,17 +101,11 @@ static struct st_hash_type type_strhash 
 #define xcalloc  calloc
 #define xrealloc realloc
 #define xfree    free
-#if 0
-void *xmalloc(long);
-void *xcalloc(long, long);
-void *xrealloc(void *, long);
-void xfree(void *);
-#endif
 
 static void rehash(st_table *);
 
-#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
-#define Calloc(n,s) (char*)xcalloc((n),(s))
+#define alloc(type) (type*)xmalloc(sizeof(type))
+#define Calloc(n,s) (char*)xcalloc((n), (s))
 
 #define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)(((void*)x),((void *)y)) == 0)
 
@@ -200,7 +193,7 @@ stat_col()
 st_table*
 st_init_table_with_size(type, size)
      struct st_hash_type *type;
-     int size;
+     size_t size;
 {
   st_table *tbl;
 
@@ -238,7 +231,7 @@ st_init_numtable(void)
 
 st_table*
 st_init_numtable_with_size(size)
-     int size;
+     size_t size;
 {
   return st_init_table_with_size(&type_numhash, size);
 }
@@ -251,7 +244,7 @@ st_init_strtable(void)
 
 st_table*
 st_init_strtable_with_size(size)
-     int size;
+     size_t size;
 {
   return st_init_table_with_size(&type_strhash, size);
 }
@@ -314,7 +307,8 @@ st_lookup(table, key, value)
     return 0;
   }
   else {
-    if (value != 0)  *value = ptr->record;
+    if (value != 0)
+      *value = ptr->record;
     return 1;
   }
 }
@@ -407,7 +401,8 @@ st_copy(old_table)
 {
   st_table *new_table;
   st_table_entry *ptr, *entry;
-  int i, num_bins = old_table->num_bins;
+  int i;
+  size_t num_bins = old_table->num_bins;
 
   new_table = alloc(st_table);
   if (new_table == 0)
@@ -417,7 +412,7 @@ st_copy(old_table)
 
   *new_table = *old_table;
   new_table->bins = (st_table_entry**)
-    Calloc((unsigned)num_bins, sizeof(st_table_entry*));
+    Calloc(num_bins, sizeof(st_table_entry*));
 
   if (new_table->bins == 0)
   {
@@ -524,7 +519,7 @@ st_delete_safe(table, key, value, never)
 }
 
 static int
-delete_never( st_data_t key, st_data_t value, st_data_t never)
+delete_never(st_data_t key, st_data_t value, st_data_t never)
 {
   if (value == never) return ST_DELETE;
   return ST_CONTINUE;



More information about the general mailing list