commit 485bc1e1d7c1ab76966fa53235f16c172cd4f708
Author: Oswald Buddenhagen <[email protected]>
Date: Fri Nov 15 20:20:45 2019 +0100
rewrite nonsensical struct packing magic
this couldn't have possibly worked - the alignment also determines the
sizeof, thus defeating the intent of the packing.
src/common.h | 24 +++++++++++++-----------
src/util.c | 3 ++-
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/common.h b/src/common.h
index 4f27ebd..3264f79 100644
--- a/src/common.h
+++ b/src/common.h
@@ -47,12 +47,10 @@ typedef unsigned long ulong;
# define ATTR_UNUSED __attribute__((unused))
# define ATTR_NORETURN __attribute__((noreturn))
# define ATTR_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
-# define ATTR_PACKED(ref) __attribute__((packed,aligned(sizeof(ref))))
#else
# define ATTR_UNUSED
# define ATTR_NORETURN
# define ATTR_PRINTFLIKE(fmt,var)
-# define ATTR_PACKED(ref)
#endif
#if defined(__clang__)
@@ -136,7 +134,7 @@ void flushn( void );
typedef struct string_list {
struct string_list *next;
char string[1];
-} ATTR_PACKED(void *) string_list_t;
+} string_list_t;
void add_string_list_n( string_list_t **list, const char *str, uint len );
void add_string_list( string_list_t **list, const char *str );
@@ -175,22 +173,26 @@ int map_name( const char *arg, char **result, uint
reserve, const char *in, cons
typedef struct { \
T *data; \
uint size; \
- } ATTR_PACKED(T *) T##_array_t; \
- typedef struct { \
+ } T##_array_t; \
+ typedef union { \
T##_array_t array; \
- uint alloc; \
- } ATTR_PACKED(T *) T##_array_alloc_t; \
+ struct { \
+ T *dummy_data; \
+ uint dummy_size; \
+ uint alloc; \
+ } extra; \
+ } T##_array_alloc_t; \
static INLINE T *T##_array_append( T##_array_alloc_t *arr ) \
{ \
- if (arr->array.size == arr->alloc) { \
- arr->alloc = arr->alloc * 2 + 100; \
- arr->array.data = nfrealloc( arr->array.data,
arr->alloc * sizeof(T) ); \
+ if (arr->array.size == arr->extra.alloc) { \
+ arr->extra.alloc = arr->extra.alloc * 2 + 100; \
+ arr->array.data = nfrealloc( arr->array.data,
arr->extra.alloc * sizeof(T) ); \
} \
return &arr->array.data[arr->array.size++]; \
}
#define ARRAY_INIT(arr) \
- do { (arr)->array.data = NULL; (arr)->array.size = (arr)->alloc = 0; }
while (0)
+ do { (arr)->array.data = NULL; (arr)->array.size = (arr)->extra.alloc =
0; } while (0)
#define ARRAY_SQUEEZE(arr) \
do { \
diff --git a/src/util.c b/src/util.c
index 7815dbc..46b4c6a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
#include <assert.h>
#include <limits.h>
+#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -168,7 +169,7 @@ add_string_list_n( string_list_t **list, const char *str,
uint len )
{
string_list_t *elem;
- elem = nfmalloc( sizeof(*elem) + len );
+ elem = nfmalloc( offsetof(string_list_t, string) + len + 1 );
elem->next = *list;
*list = elem;
memcpy( elem->string, str, len );
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel