Skip to content

Instantly share code, notes, and snippets.

@irisfofs
Created April 26, 2016 19:13
Show Gist options
  • Save irisfofs/52c76ec67ff0bc4d722c16d06c43443c to your computer and use it in GitHub Desktop.
Save irisfofs/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