diff options
-rw-r--r-- | smbutil.c | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -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<len; ++i) { @@ -122,7 +121,7 @@ static unsigned char *strToUnicode(char *p) size_t l = strlen(p); int i = 0; - allocbuf((char **)&buf, &bufsiz, l * 2); + allocbuf(buf, bufsiz, l * 2); while (l--) { @@ -138,7 +137,7 @@ static unsigned char *toString(char *p, size_t len) static unsigned char *buf; static size_t bufsiz; - allocbuf((char **)&buf, &bufsiz, len + 1); + allocbuf(buf, bufsiz, len + 1); memcpy(buf,p,len); buf[len] = 0; |