changed the size of a char array in the userdata_struct from 1 to 16
authorAndrew Tridgell <tridge@samba.org>
Sun, 30 Aug 1998 04:30:57 +0000 (04:30 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 30 Aug 1998 04:30:57 +0000 (04:30 +0000)
to account for padding/alignment issues. Eventually I'd like to find a
way to get rid of this construct altogether as it is a bit error
prone and hard to debug.

also added a new macro:

ZERO_STRUCTP() that takes a pointer to a structure and zeros the
structure. Used in nmbd to zero allocated structures before freeing
them to try to catch bugs a bit faster.

source/include/nameserv.h
source/include/proto.h
source/include/smb.h

index 80d9667d1c35f162f5327ae832dc6a16bee97c1c..fe00a1415d5cd8d7ae79d9d0c9de76366ca2381a 100644 (file)
@@ -278,7 +278,7 @@ struct userdata_struct {
   userdata_copy_fn copy_fn;
   userdata_free_fn free_fn;
   unsigned int userdata_len;
-  char data[1];
+  char data[16]; /* 16 is to ensure alignment/padding on all systems */
 };
 
 struct response_record;
index 6594ac6143a0201c99ac47ce9fe1b52856ea2382..991e4f3e31d1ad00a765b2c9574395f8577cb251 100644 (file)
@@ -356,6 +356,7 @@ char *tab_depth(int depth);
 char *sid_to_string(pstring sidstr_out, DOM_SID *sid);
 BOOL string_to_sid(DOM_SID *sidout, char *sidstr);
 int str_checksum(char *s);
+void zero_free(void *p, int size);
 
 /*The following definitions come from  libsmb/clientgen.c  */
 
index b615d0970838bbf1c31f8deb197672de34caef78..90435b208e3115a95abc6d9eb1a86229eaebf474 100644 (file)
@@ -1569,8 +1569,17 @@ extern int unix_ERR_code;
 #define CMD_REPLY 0x8000
 
 /* useful macros */
+
+/* zero a structure */
 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+/* zero a structure given a pointer to the structure */
+#define ZERO_STRUCTP(x) memset((char *)(x), 0, sizeof(*(x)))
+
+/* zero an array - note that sizeof(array) must work - ie. it must not be a 
+   pointer */
 #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
+
 #define SMB_ASSERT(b) ((b)?(void)0: \
         (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
                 __FILE__, __LINE__)), smb_panic("assert failed")))