<p>In <a href="https://github.com/geany/geany-plugins/pull/324#discussion_r49536019">lineoperations/src/linefunctions.c</a>:</p>
<pre style='color:#555'>> +    newfile       = g_malloc(sizeof(gchar) * (totalnumchars+1));
> +  numlines      = 0;
> +  nfposn        = 0;
> +  k             = 0;
> +
> +  if(newfile && lines)    // verify memory allocation
> +  {
> +          // copy *all* lines into **lines array
> +          for(i = 0; i < totalnumlines; i++)
> +                  lines[numlines++] = sci_get_line(doc->editor->sci, i);
> +
> +          qsort(lines, numlines, sizeof(gchar *), compareasc);
> +
> +          if(numlines > 0)     // copy the first line into *newfile
> +                  for(j = 0; lines[0][j] != '\0'; j++)
> +                          newfile[nfposn++] = lines[0][j];
</pre>
<blockquote>
<p>mostly for joining array of lines into new_file string</p>
</blockquote>

<p>Not sure if it's applicable here (didn't really look at the code), but if you can enforce the last array element is <code>NULL</code>, you could maybe use <a href="https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strjoinv"><code>g_strjoinv()</code></a> and using <code>\n</code> as the <code>separator</code> argument.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/geany/geany-plugins/pull/324/files#r49536019">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABDrJzrmw9kK0n4_LkVZHMcJCzt6han8ks5pZZAMgaJpZM4HBhj7.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany-plugins/pull/324/files#r49536019"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>