Skip to content

Instantly share code, notes, and snippets.

@xiagu
Created April 26, 2016 19:13
Show Gist options
  • Save xiagu/52c76ec67ff0bc4d722c16d06c43443c to your computer and use it in GitHub Desktop.
Save xiagu/52c76ec67ff0bc4d722c16d06c43443c to your computer and use it in GitHub Desktop.
Snippet from Weechat's gui-completion.c. I feel like this could be rewritten with memcpy...
if (pos_start <= pos_end)
{
completion->position_replace = pos_start;
completion->base_word = malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
{
completion->base_word[i - pos_start] = data[i];
}
completion->base_word[pos_end - pos_start + 1] = '\0';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment