]> Pileus Git - ~andy/fetchmail/blobdiff - smbutil.c
Revise allocbuf to make it a macro, quenches type-aliasing warnings.
[~andy/fetchmail] / smbutil.c
index 9a8fbeef89a502d3dff1a01e5c5ad1fb14389d90..18aa1dc4c7c3ec9b7857dff21b96022b1ea6d9f5 100644 (file)
--- 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<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;