<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7267">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">CLI: Rewrite ast_el_strtoarr to use vector's internally.<br><br>This rewrites ast_el_strtoarr to use vector's internally, but still<br>return the original NULL terminated array of strings.<br><br>Change-Id: Ibfe776cbe14f750effa9ca360930acaccc02e957<br>---<br>M main/asterisk.c<br>1 file changed, 22 insertions(+), 39 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/67/7267/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/asterisk.c b/main/asterisk.c<br>index 2908b46..46dc9a7 100644<br>--- a/main/asterisk.c<br>+++ b/main/asterisk.c<br>@@ -3001,64 +3001,47 @@<br> return ast_str_buffer(prompt);<br> }<br> <br>-static void destroy_match_list(char **match_list, int matches)<br>-{<br>- if (match_list) {<br>- int idx;<br>-<br>- for (idx = 0; idx < matches; ++idx) {<br>- ast_free(match_list[idx]);<br>- }<br>- ast_free(match_list);<br>- }<br>-}<br>-<br> static char **ast_el_strtoarr(char *buf)<br> {<br> char *retstr;<br>- char **match_list = NULL;<br>- char **new_list;<br>- size_t match_list_len = 1;<br>- int matches = 0;<br>+ char **match_list;<br>+ struct ast_vector_string *vec = ast_calloc(1, sizeof(*vec));<br>+<br>+ if (!vec) {<br>+ return NULL;<br>+ }<br> <br> while ((retstr = strsep(&buf, " "))) {<br> if (!strcmp(retstr, AST_CLI_COMPLETE_EOF)) {<br> break;<br> }<br>- if (matches + 1 >= match_list_len) {<br>- match_list_len <<= 1;<br>- new_list = ast_realloc(match_list, match_list_len * sizeof(char *));<br>- if (!new_list) {<br>- destroy_match_list(match_list, matches);<br>- return NULL;<br>- }<br>- match_list = new_list;<br>- }<br> <br> retstr = ast_strdup(retstr);<br>- if (!retstr) {<br>- destroy_match_list(match_list, matches);<br>- return NULL;<br>+ if (!retstr || AST_VECTOR_APPEND(vec, retstr)) {<br>+ ast_free(retstr);<br>+ goto vector_cleanup;<br> }<br>- match_list[matches++] = retstr;<br> }<br> <br>- if (!match_list) {<br>- return NULL;<br>+ if (!AST_VECTOR_SIZE(vec)) {<br>+ goto vector_cleanup;<br> }<br> <br>- if (matches >= match_list_len) {<br>- new_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *));<br>- if (!new_list) {<br>- destroy_match_list(match_list, matches);<br>- return NULL;<br>- }<br>- match_list = new_list;<br>+ if (AST_VECTOR_APPEND(vec, NULL)) {<br>+ /* We failed to NULL terminate the elements */<br>+ goto vector_cleanup;<br> }<br> <br>- match_list[matches] = NULL;<br>+ match_list = AST_VECTOR_STEAL_ELEMENTS(vec);<br>+ AST_VECTOR_PTR_FREE(vec);<br> <br> return match_list;<br>+<br>+vector_cleanup:<br>+ AST_VECTOR_CALLBACK_VOID(vec, ast_free);<br>+ AST_VECTOR_PTR_FREE(vec);<br>+<br>+ return NULL;<br> }<br> <br> static int ast_el_sort_compare(const void *i1, const void *i2)<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7267">change 7267</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/7267"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ibfe776cbe14f750effa9ca360930acaccc02e957 </div>
<div style="display:none"> Gerrit-Change-Number: 7267 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>