<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - shared: strv_extend_strv is quadratic"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=76746">76746</a>
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>systemd-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>shared: strv_extend_strv is quadratic
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>systemd-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mustrumr97@gmail.com
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>general
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>systemd
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Depends on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - shared: strv can't have more than 4294967295 elements"
   href="show_bug.cgi?id=76745">bug 76745</a>

strv_extend_strv(a, b)

Current implementation: O(|a|*|b|+sum(i in b,strlen(i)))

Non-retard implementation: O(|a|+|b|+sum(i in b,strlen(i)))

int strv_extend_strv(char ***a, **b){
    size_t n=strv_length(*a), m=strv_length(b), i;

    char **tmp=realloc(*a, sizeof(char*)*(n+m+1));
    if(!tmp) return -ENOMEM;
    *a=tmp;
    for(i=0;i<m;i++){
        tmp[n+i]=strdup(b[i]);
        if(!tmp[n+i]) return -ENOMEM;
    }
    a[n+m]=NULL;
    return 0;
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>