diff options
-rw-r--r-- | pw.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -26,6 +26,7 @@ // POSSIBILITY OF SUCH DAMAGE. #include <assert.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -130,7 +131,7 @@ typedef struct dstr { char str[]; } dstr; -#define dstr_of(str) ((dstr *) ((str) - sizeof (dstr))) +#define dstr_of(s) ((dstr *) ((s) - offsetof (struct dstr, str))) static char *pw_name; static int poll_interval = 1000; @@ -203,7 +204,7 @@ static char *dsgrow(char *str, size_t len) { dstr *ds = str ? dstr_of(str) : 0; int flags = str ? ds->flags : 0; - size_t size = sizeof *ds + len + 1; + size_t size = offsetof(struct dstr, str) + len + 1; assert (ds == 0 || ds->refs == 1); |