Browse Source

assert sizes of smaller-than-int bit fields in structures

wip/maildir-path-under-inbox
Oswald Buddenhagen 3 years ago
parent
commit
608c724add
  1. 4
      src/common.h
  2. 5
      src/driver.h
  3. 3
      src/sync_p.h

4
src/common.h

@ -45,6 +45,10 @@ typedef unsigned long ulong;
#define BIT_ENUM(...) #define BIT_ENUM(...)
#define static_assert_bits(pfx, type, field) \
static_assert( pfx##__NUM_BITS <= sizeof(((type){ 0 }).field) * 8, \
stringify(type) "::" stringify(field) " is too small" )
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
# define ATTR_UNUSED __attribute__((unused)) # define ATTR_UNUSED __attribute__((unused))
# define ATTR_NORETURN __attribute__((noreturn)) # define ATTR_NORETURN __attribute__((noreturn))

5
src/driver.h

@ -74,6 +74,9 @@ typedef struct message {
MESSAGE(struct message) MESSAGE(struct message)
} message_t; } message_t;
static_assert_bits(F, message_t, flags);
static_assert_bits(M, message_t, status);
// For driver_t->prepare_load_box(), which may amend the passed flags. // For driver_t->prepare_load_box(), which may amend the passed flags.
// The drivers don't use the first two, but may set them if loading the // The drivers don't use the first two, but may set them if loading the
// particular range is required to handle some other flag; note that these // particular range is required to handle some other flag; note that these
@ -108,6 +111,8 @@ typedef struct {
uchar flags; uchar flags;
} msg_data_t; } msg_data_t;
static_assert_bits(F, msg_data_t, flags);
#define DRV_OK 0 #define DRV_OK 0
/* Message went missing, or mailbox is full, etc. */ /* Message went missing, or mailbox is full, etc. */
#define DRV_MSG_BAD 1 #define DRV_MSG_BAD 1

3
src/sync_p.h

@ -36,6 +36,9 @@ typedef struct sync_rec {
char tuid[TUIDL]; char tuid[TUIDL];
} sync_rec_t; } sync_rec_t;
static_assert_bits(F, sync_rec_t, flags);
static_assert_bits(S, sync_rec_t, status);
typedef struct { typedef struct {
int t[2]; int t[2];
void (*cb)( int sts, void *aux ), *aux; void (*cb)( int sts, void *aux ), *aux;

Loading…
Cancel
Save