diff options
author | Runxi Yu <me@runxiyu.org> | 1970-01-01 00:00:00 +0000 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-07-24 01:04:53 -0400 |
commit | daa4cd4177690641a8fc29b836824856abf60711 (patch) | |
tree | 6c147979564bf87f9f784dd15eb9e65acfa59bf0 | |
parent | 6bda8db538d8d9edbca3f607698f828c763966b2 (diff) | |
download | haxircd-daa4cd4177690641a8fc29b836824856abf60711.tar.gz haxircd-daa4cd4177690641a8fc29b836824856abf60711.zip |
haxstring: Add parenthesis to macro arguments
WRITES(fd, *s) where s is a pointer to a struct string will
not compile, as the macro expands to write(fd, *s.data, *s.len),
which it expects s to be a struct string and attempts to use
s.data and s.len as pointers. This is, of course, erroneous.
The correct expansion is write(fd, (*s).data, (*s).len); while
write(fd, s->data, s->len) is desirable, it is not achievable with
a simple macro expansion. In any case, the parenthesis shall be
added.
-rw-r--r-- | haxstring.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/haxstring.h b/haxstring.h index 0c72ff3..f0c3947 100644 --- a/haxstring.h +++ b/haxstring.h @@ -40,6 +40,6 @@ struct string { #define STRING(x) (struct string){x, sizeof(x)-1} #define NULSTR(x) (struct string){x, strlen(x)} -#define STRING_EQ(x, y) (x.len == y.len && memcmp(x.data, y.data, x.len) == 0) +#define STRING_EQ(x, y) ((x).len == (y).len && memcmp((x).data, (y).data, (x).len) == 0) -#define WRITES(x, y) write(x, y.data, y.len) +#define WRITES(x, y) write((x), (y).data, (y).len) |