[asterisk-commits] mmichelson: branch 1.4 r162670 - /branches/1.4/include/asterisk/stringfields.h

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 10 10:44:38 CST 2008


Author: mmichelson
Date: Wed Dec 10 10:44:37 2008
New Revision: 162670

URL: http://svn.digium.com/view/asterisk?view=rev&rev=162670
Log:
Update to stringfield handling so that side-effects on
parameters are not evaluated multiple times.

An example where this caused a problem was in chan_sip.c, with
the line

  ast_string_field_set(p, fromdomain, ++fromdomain);

This patch was originally uploaded to issue #13783 by
jamessan. While the issue was closed for other reasons, this
patch is valid and fixes a separate problem, and is thus
being committed.


Modified:
    branches/1.4/include/asterisk/stringfields.h

Modified: branches/1.4/include/asterisk/stringfields.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/stringfields.h?view=diff&rev=162670&r1=162669&r2=162670
==============================================================================
--- branches/1.4/include/asterisk/stringfields.h (original)
+++ branches/1.4/include/asterisk/stringfields.h Wed Dec 10 10:44:37 2008
@@ -235,16 +235,17 @@
 */
 #define ast_string_field_index_set(x, index, data) do { \
     char *__zz__ = (char*) (x)->__begin_field[index]; \
-    size_t __dlen__ = strlen(data) + 1; \
+    char *__data__ = (char*) data; \
+    size_t __dlen__ = strlen(__data__) + 1; \
     if ( __dlen__ == 1 ) {\
       (x)->__begin_field[index] = __ast_string_field_empty; \
     } else { \
       if ((__zz__[0] != 0) && (__dlen__ <= (strlen(__zz__) + 1))) { \
-        memcpy(__zz__, data, __dlen__); \
+        memcpy(__zz__, __data__, __dlen__); \
       } else { \
         if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, __dlen__, &(x)->__begin_field[0], ast_string_field_count(x)))) { \
           char *__yy__ = (char *) (x)->__begin_field[index]; \
-          memcpy(__yy__, data, __dlen__); \
+          memcpy(__yy__, __data__, __dlen__); \
         } \
       } \
      } \
@@ -252,17 +253,18 @@
 
 #define ast_string_field_index_logset(x, index, data, logstr) do { \
     char *__zz__ = (char*) (x)->__begin_field[index]; \
-    size_t __dlen__ = strlen(data) + 1; \
+    char *__data__ = (char*) data; \
+    size_t __dlen__ = strlen(__data__) + 1; \
     if ( __dlen__ == 1 ) {\
       (x)->__begin_field[index] = __ast_string_field_empty; \
     } else { \
       if ((__zz__[0] != 0) && (__dlen__ <= strlen(__zz__) + 1)) { \
-        ast_verbose("%s: ======replacing '%s' with '%s'\n", logstr, __zz__, data); \
-        memcpy(__zz__, data, __dlen__); \
+        ast_verbose("%s: ======replacing '%s' with '%s'\n", logstr, __zz__, __data__); \
+        memcpy(__zz__, __data__, __dlen__); \
       } else { \
         if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, __dlen__, &(x)->__begin_field[0], ast_string_field_count(x)))) \
-          ast_verbose("%s: ++++++allocating room for '%s' to replace '%s'\n", logstr, data, __zz__); \
-          memcpy((char*) (x)->__begin_field[index], data, __dlen__); \
+          ast_verbose("%s: ++++++allocating room for '%s' to replace '%s'\n", logstr, __data__, __zz__); \
+          memcpy((char*) (x)->__begin_field[index], __data__, __dlen__); \
       } \
      } \
    } while (0)




More information about the asterisk-commits mailing list