<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6662">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vector: multiple evaluation of elem in AST_VECTOR_ADD_SORTED.<br><br>Use temporary variable to prevent multiple evaluations of elem argument.<br>This resolves a memory leak in res_pjproject startup.<br><br>ASTERISK-27317 #close<br><br>Change-Id: Ib960d7f5576f9e1a3c478ecb48995582a574e06d<br>---<br>M include/asterisk/vector.h<br>M tests/test_vector.c<br>2 files changed, 8 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h<br>index 2de84d2..1e6fe03 100644<br>--- a/include/asterisk/vector.h<br>+++ b/include/asterisk/vector.h<br>@@ -304,27 +304,31 @@<br> * \brief Add an element into a sorted vector<br> *<br> * \param vec Sorted vector to add to.<br>- * \param elem Element to insert.<br>+ * \param elem Element to insert. Must not be an array type.<br> * \param cmp A strcmp compatible compare function.<br> *<br> * \return 0 on success.<br> * \return Non-zero on failure.<br> *<br> * \warning Use of this macro on an unsorted vector will produce unpredictable results<br>+ * \warning 'elem' must not be an array type so passing 'x' where 'x' is defined as<br>+ * 'char x[4]' will fail to compile. However casting 'x' as 'char *' does<br>+ * result in a value that CAN be used.<br> */<br> #define AST_VECTOR_ADD_SORTED(vec, elem, cmp) ({ \<br> int res = 0; \<br> size_t __idx = (vec)->current; \<br>+ typeof(elem) __elem = (elem); \<br> do { \<br> if (__make_room((vec)->current, vec) != 0) { \<br> res = -1; \<br> break; \<br> } \<br>- while (__idx > 0 && (cmp((vec)->elems[__idx - 1], elem) > 0)) { \<br>+ while (__idx > 0 && (cmp((vec)->elems[__idx - 1], __elem) > 0)) { \<br> (vec)->elems[__idx] = (vec)->elems[__idx - 1]; \<br> __idx--; \<br> } \<br>- (vec)->elems[__idx] = elem; \<br>+ (vec)->elems[__idx] = __elem; \<br> (vec)->current++; \<br> } while (0); \<br> res; \<br>diff --git a/tests/test_vector.c b/tests/test_vector.c<br>index 8e0d121..2dfcc60 100644<br>--- a/tests/test_vector.c<br>+++ b/tests/test_vector.c<br>@@ -210,7 +210,7 @@<br> ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, ZZZ, strcmp) == 0, rc, cleanup);<br> ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, CCC, strcmp) == 0, rc, cleanup);<br> ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, AAA, strcmp) == 0, rc, cleanup);<br>- ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, CCC2, strcmp) == 0, rc, cleanup);<br>+ ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, (char*)CCC2, strcmp) == 0, rc, cleanup);<br> <br> ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 0) == AAA, rc, cleanup);<br> ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 1) == BBB, rc, cleanup);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6662">change 6662</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6662"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib960d7f5576f9e1a3c478ecb48995582a574e06d </div>
<div style="display:none"> Gerrit-Change-Number: 6662 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>