aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pw.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/pw.c b/pw.c
index 29b4cb5..a2ddff0 100644
--- a/pw.c
+++ b/pw.c
@@ -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);