[asterisk-commits] kpfleming: trunk r155079 - /trunk/include/asterisk/strings.h

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 6 15:09:24 CST 2008


Author: kpfleming
Date: Thu Nov  6 15:09:24 2008
New Revision: 155079

URL: http://svn.digium.com/view/asterisk?view=rev&rev=155079
Log:
make S_OR and S_COR safe to use even if the parameters are function calls or have side effects. it still bothers me that these are called S_OR and not something like ast_string_or, but that's water over the bridge


Modified:
    trunk/include/asterisk/strings.h

Modified: trunk/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/strings.h?view=diff&rev=155079&r1=155078&r2=155079
==============================================================================
--- trunk/include/asterisk/strings.h (original)
+++ trunk/include/asterisk/strings.h Thu Nov  6 15:09:24 2008
@@ -52,13 +52,19 @@
 /*! \brief returns the equivalent of logic or for strings:
  * first one if not empty, otherwise second one.
  */
-#define S_OR(a, b)           (!ast_strlen_zero(a) ? (a) : (b))
+static force_inline char *S_OR(const char *a, const char *b)
+{
+	return ast_strlen_zero(a) ? (char *) b : (char *) a;
+}
 
 /*! \brief returns the equivalent of logic or for strings, with an additional boolean check:
  * second one if not empty and first one is true, otherwise third one.
  * example: S_COR(usewidget, widget, "<no widget>")
  */
-#define S_COR(a, b, c)   ((a && !ast_strlen_zero(b)) ? (b) : (c))
+static force_inline char *S_COR(unsigned char a, const char *b, const char *c)
+{
+	return a && !ast_strlen_zero(b) ? (char *) b : (char *) c;
+}
 
 /*!
   \brief Gets a pointer to the first non-whitespace character in a string.




More information about the asterisk-commits mailing list