[geany/geany] 484f6f: Make sure to only use as much data as it was actually read

Colomban Wendling git-noreply at xxxxx
Sat Aug 25 14:02:21 UTC 2012


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sat, 25 Aug 2012 14:02:21
Commit:      484f6fcdef245a1501bc93a124a68f0f3d273b5d
             https://github.com/geany/geany/commit/484f6fcdef245a1501bc93a124a68f0f3d273b5d

Log Message:
-----------
Make sure to only use as much data as it was actually read

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.


Modified Paths:
--------------
    tagmanager/ctags/get.c

Modified: tagmanager/ctags/get.c
8 files changed, 5 insertions(+), 3 deletions(-)
===================================================================
@@ -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);


@@ Diff output truncated at 100000 characters. @@


--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).



More information about the Commits mailing list