[openib-general] RE: 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:15 PST 2006


Hi Hal,
That is because I accidentally sent the original patch....
The fix is in line 404 - make i of size_t (instead of int) as well.
I will send that patch separately.
Yael

-----Original Message-----
From: Hal Rosenstock [mailto:halr at voltaire.com] 
Sent: Monday, February 20, 2006 5:28 PM
To: Yael Kalka
Cc: openib-general at openib.org; Eitan Zahavi
Subject: Re: Re:[PATCH] OpenSM/st.c: Fix some size_t issues related
tomemoryallocation in st.c

Hi Yael,

On Sun, 2006-02-19 at 07:24, Yael Kalka wrote:
> Hi Hal,
> 
> The patch in general is fine. I've added one change to the original
> patch - to avoid casting issues underwindows
> Below is the full patch.

This looks like the same patch to me. What changed ? (What did I miss ?)

-- Hal

> 
> Yael
> 
> 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