Skip to content

Commit

Permalink
Make sure to only use as much data as it was actually read
Browse files Browse the repository at this point in the history
When reading a C macro, make sure to only use as much byes we actually
got and not as much as we requested.  This should not be a problem
anymore now 61c5216 fixed a too long read, but it's safer anyway.
  • Loading branch information
b4n committed Aug 25, 2012
1 parent 61c5216 commit 484f6fc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tagmanager/ctags/get.c
Expand Up @@ -722,10 +722,12 @@ extern char *getArglistFromFilePos(MIOPos startPosition, const char *tokenName)

if (pos2 > pos1)
{
result = (char *) g_malloc(sizeof(char ) * (pos2 - pos1 + 1));
if (result != NULL && mio_read(File.mio, result, sizeof(char), pos2 - pos1) > 0)
size_t len = pos2 - pos1;

result = (char *) g_malloc(len + 1);
if (result != NULL && (len = mio_read(File.mio, result, 1, len)) > 0)
{
result[pos2-pos1] = '\0';
result[len] = '\0';
arglist = getArglistFromStr(result, tokenName);
}
g_free(result);
Expand Down

0 comments on commit 484f6fc

Please sign in to comment.