<pre style='margin:0'>
Umesh Singla (umeshksingla) pushed a commit to branch gsoc17-migrate
in repository macports-base.

</pre>
<p><a href="https://github.com/macports/macports-base/commit/272ae31859ae566fb3ee6372431c76396e171437">https://github.com/macports/macports-base/commit/272ae31859ae566fb3ee6372431c76396e171437</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/gsoc17-migrate by this push:
<span style='display:block; white-space:pre;color:#404040;'>     new 272ae31  Refactor constructing variant string
</span>272ae31 is described below

<span style='display:block; white-space:pre;color:#808000;'>commit 272ae31859ae566fb3ee6372431c76396e171437
</span>Author: Umesh Singla <umeshksingla@gmail.com>
AuthorDate: Sat Mar 10 17:38:46 2018 +0100

<span style='display:block; white-space:pre;color:#404040;'>    Refactor constructing variant string
</span>---
 src/cregistry/snapshot.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/snapshot.c b/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 74ad906..36b629a 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -464,20 +464,26 @@ int reg_snapshot_ports_get(reg_snapshot* snapshot, port*** ports, reg_error* err
</span> 
                     char* variantstr = NULL;
                     if (current_port->variant_count > 0) {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        int j;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                        variantstr = NULL;
</span>                         // construct the variant string in the form '+var1-var2+var3'
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        for(j = 0; j < current_port->variant_count; j++) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                            if (asprintf(&variantstr, "%s%s",
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    (*variants)[j].variant_sign,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    (*variants)[j].variant_name) < 0) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                            }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        size_t variantstrlen = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        for (int j = 0; j < current_port->variant_count; ++j) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            variantstrlen += strlen(variants[j]->variant_sign);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            variantstrlen += strlen(variants[j]->variant_name);
</span>                         }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        current_port->variants = strdup(variantstr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                        free(variantstr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        // +1 for \0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        variantstr = malloc(variantstrlen + 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        if (!variantstr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        variantstr[0] = '\0';
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        for (int j = 0; j < current_port->variant_count; ++j) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            strcat(variantstr, variants[j]->variant_sign);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            strcat(variantstr, variants[j]->variant_name);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        current_port->variants = variantstr;
</span>                     } else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        current_port->variants = "\0";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        current_port->variants = strdup("\0");
</span>                     }
 
                     if (!reg_listcat((void***)&result, &result_count, &result_space, current_port)) {
</pre><pre style='margin:0'>

</pre>