S
Serve Lau
Some of you may be aware of the "bucket technique" to create linked lists or
any data structure in C in a general way. I was wondering if there's any UB
involved in the following snippet, especially newsym/freesym functions and
when the returned pointer is used in between
typedef struct BUCKET {
struct fs_BUCKET *Next;
struct fs_BUCKET **Prev;
} BUCKET;
typedef struct DATA_LIST {
size_t Size;
BUCKET *First;
} DATA_LIST;
void *newsym(size_t Size) {
BUCKET *p = malloc(Size + sizeof *p);
return p ? p + 1 : NULL;
}
void freesym(void *p) {
free((BUCKET *)p - 1);
}
any data structure in C in a general way. I was wondering if there's any UB
involved in the following snippet, especially newsym/freesym functions and
when the returned pointer is used in between
typedef struct BUCKET {
struct fs_BUCKET *Next;
struct fs_BUCKET **Prev;
} BUCKET;
typedef struct DATA_LIST {
size_t Size;
BUCKET *First;
} DATA_LIST;
void *newsym(size_t Size) {
BUCKET *p = malloc(Size + sizeof *p);
return p ? p + 1 : NULL;
}
void freesym(void *p) {
free((BUCKET *)p - 1);
}