From e9792090c892be910c634803b2a3839e061cf4e4 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Mon, 25 May 2009 21:59:14 +0000 Subject: Revise allocbuf to make it a macro, quenches type-aliasing warnings. svn path=/branches/BRANCH_6-3/; revision=5341 --- smbutil.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'smbutil.c') diff --git a/smbutil.c b/smbutil.c index 9a8fbeef..18aa1dc4 100644 --- a/smbutil.c +++ b/smbutil.c @@ -82,17 +82,16 @@ static void dumpRaw(FILE *fp, unsigned char *buf, size_t len) fprintf(fp,"\n"); } -/* helper function to destructively resize buffers; assumes that bufsiz +/* helper macro to destructively resize buffers; assumes that bufsiz * is initialized to 0 if buf is unallocated! */ -static void allocbuf(char **buf, size_t *bufsiz, size_t need) - { - if (need > *bufsiz) - { - *bufsiz = (need < 1024) ? 1024 : need; - xfree(*buf); - *buf = xmalloc(*bufsiz); - } - } +#define allocbuf(buf, bufsiz, need) do { \ + if ((need) > (bufsiz)) \ + { \ + (bufsiz) = ((need) < 1024) ? 1024 : (need); \ + xfree(buf); \ + (buf) = xmalloc(bufsiz); \ + } \ + } while (0); /* this is a brute-force conversion from UCS-2LE to US-ASCII, discarding * the upper 9 bits */ @@ -102,7 +101,7 @@ static char *unicodeToString(char *p, size_t len) static char *buf; static size_t bufsiz; - allocbuf(&buf, &bufsiz, len + 1); + allocbuf(buf, bufsiz, len + 1); for (i=0; i