[openib-general] Re:[PATCH] OpenSM/st.c: Fix some size_t issues related tomemoryallocation in st.c
Yael Kalka
yael at mellanox.co.il
Mon Feb 20 23:10:31 PST 2006
Hi Hal,
Here is the patch with the fix for the type of "i".
patch - to avoid casting issues underwindows
Below is the full patch.
Yael
Signed-off-by: Hal Rosenstock <halr at voltaire.com>
Index: include/opensm/st.h
===================================================================
--- include/opensm/st.h (revision 5446)
+++ 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 5446)
+++ 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,16 +101,10 @@ 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 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,7 @@ st_copy(old_table)
{
st_table *new_table;
st_table_entry *ptr, *entry;
- int i, num_bins = old_table->num_bins;
+ size_t i, num_bins = old_table->num_bins;
new_table = alloc(st_table);
if (new_table == 0)
@@ -417,7 +411,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)
{
More information about the general
mailing list