pyldb: avoid segfault when adding an element with no name
[sfrench/samba-autobuild/.git] / lib / replace / replace.h
index 0055255a9a5f391e2ef9beceac98219995fefeb0..4d9b81f6825bf3dddb4103624de7a43416a6860c 100644 (file)
 #include <standards.h>
 #endif
 
-/* Needs to be defined before std*.h and string*.h are included */
-#define __STDC_WANT_LIB_EXT1__ 1
+/*
+ * Needs to be defined before std*.h and string*.h are included
+ * As it's also needed when Python.h is the first header we
+ * require a global -D__STDC_WANT_LIB_EXT1__=1
+ */
+#ifndef __STDC_WANT_LIB_EXT1__
+#error -D__STDC_WANT_LIB_EXT1__=1 required
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -56,7 +62,7 @@
 #ifdef HAVE_INTTYPES_H
 #define __STDC_FORMAT_MACROS
 #include <inttypes.h>
-#elif HAVE_STDINT_H
+#elif defined(HAVE_STDINT_H)
 #include <stdint.h>
 /* force off HAVE_INTTYPES_H so that roken doesn't try to include both,
    which causes a warning storm on irix */
@@ -805,32 +811,38 @@ typedef unsigned long long ptrdiff_t ;
 #define __location__ __FILE__ ":" __LINESTR__
 #endif
 
-/** 
- * zero a structure 
+/**
+ * Zero a structure.
  */
-#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+#define ZERO_STRUCT(x) memset_s((char *)&(x), sizeof(x), 0, sizeof(x))
 
-/** 
- * zero a structure given a pointer to the structure 
+/**
+ * Zero a structure given a pointer to the structure.
  */
-#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
+#define ZERO_STRUCTP(x) do { \
+       if ((x) != NULL) { \
+               memset_s((char *)(x), sizeof(*(x)), 0, sizeof(*(x))); \
+       } \
+} while(0)
 
-/** 
- * zero a structure given a pointer to the structure - no zero check 
+/**
+ * Zero a structure given a pointer to the structure - no zero check
  */
-#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
+#define ZERO_STRUCTPN(x) memset_s((char *)(x), sizeof(*(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))
+/**
+ * Zero an array - note that sizeof(array) must work - ie. it must not be a
+ * pointer
+ */
+#define ZERO_ARRAY(x) memset_s((char *)(x), sizeof(x), 0, sizeof(x))
 
 /**
- * work out how many elements there are in a static array 
+ * Work out how many elements there are in a static array.
  */
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
-/** 
- * pointer difference macro 
+/**
+ * Pointer difference macro
  */
 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
 
@@ -846,6 +858,10 @@ typedef unsigned long long ptrdiff_t ;
 #define PATH_MAX 1024
 #endif
 
+#ifndef NAME_MAX
+#define NAME_MAX 255
+#endif
+
 #ifndef MAX_DNS_NAME_LENGTH
 #define MAX_DNS_NAME_LENGTH 256 /* Actually 255 but +1 for terminating null. */
 #endif