[PATCH:xfindproxy] Convert STRING_BYTES & STORE_STRING from macros to inline functions

Alan Coopersmith alan.coopersmith at oracle.com
Fri Aug 24 21:27:47 PDT 2012


Solves gcc errors from passing an auto-allocated array in some of the calls:
xfindproxy.c:288:20: error: the address of ‘authName’ will always evaluate as ‘true’
xfindproxy.c:288:20: error: the address of ‘authName’ will always evaluate as ‘true’
xfindproxy.c:302:2: error: the address of ‘authName’ will always evaluate as ‘true’

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 xfindproxy.h |   31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/xfindproxy.h b/xfindproxy.h
index b755043..9eb84fd 100644
--- a/xfindproxy.h
+++ b/xfindproxy.h
@@ -47,9 +47,11 @@ from The Open Group.
  * Compute the number of bytes for a STRING representation
  */
 
-#define STRING_BYTES(_str) (2 + (_str ? strlen (_str) : 0) + \
-		     PAD64 (2 + (_str ? strlen (_str) : 0)))
-
+static inline int
+STRING_BYTES(const char *string) {
+    int len = string ? strlen (string) : 0;
+    return (2 + len + PAD64 (2 + len));
+}
 
 
 #define SKIP_STRING(_pBuf, _swap) \
@@ -71,18 +73,21 @@ from The Open Group.
     _pBuf += 2; \
 }
 
-#define STORE_STRING(_pBuf, _string) \
-{ \
-    int _len = _string ? strlen (_string) : 0; \
-    STORE_CARD16 (_pBuf, _len); \
-    if (_len) { \
-        memcpy (_pBuf, _string, _len); \
-        _pBuf += _len; \
-    } \
-    if (PAD64 (2 + _len)) \
-        _pBuf += PAD64 (2 + _len); \
+static inline char *
+store_string(char *pBuf, const char *string)
+{
+    int len = string ? strlen (string) : 0;
+    STORE_CARD16 (pBuf, len);
+    if (len) {
+        memcpy (pBuf, string, len);
+        pBuf += len;
+    }
+    if (PAD64 (2 + len))
+        pBuf += PAD64 (2 + len);
+    return pBuf;
 }
 
+#define STORE_STRING(_pBuf, _string) _pBuf = store_string(_pBuf, _string)
 
 /*
  * EXTRACT macros
-- 
1.7.9.2



More information about the xorg-devel mailing list