diff options
author | mmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-10 16:44:37 +0000 |
---|---|---|
committer | mmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-10 16:44:37 +0000 |
commit | 790b2964ea967fb9554ac9ecf3013f771817ea91 (patch) | |
tree | c5162cd43dcfe26ff76a2aa39213028c51bfc897 /include/asterisk | |
parent | 742a9b5bee8ca579a4f670116f789335114f7492 (diff) |
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.
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@162670 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/stringfields.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h index ac9481156..e1b0265aa 100644 --- a/include/asterisk/stringfields.h +++ b/include/asterisk/stringfields.h @@ -235,16 +235,17 @@ void __ast_string_field_index_build_va(struct ast_string_field_mgr *mgr, */ #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 @@ void __ast_string_field_index_build_va(struct ast_string_field_mgr *mgr, #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) |