diff src/os_unix.c @ 11281:2e6a0ea76a0d v8.0.0526

patch 8.0.0526: Coverity complains about possible negative value commit https://github.com/vim/vim/commit/85325f839a14212c7d517a4cb3464c347bfd0c1e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 30 21:18:45 2017 +0200 patch 8.0.0526: Coverity complains about possible negative value Problem: Coverity complains about possible negative value. Solution: Check return value of ftell() not to be negative.
author Christian Brabandt <cb@256bit.org>
date Thu, 30 Mar 2017 21:30:05 +0200
parents d7c1d5f7cf2a
children 7e5e76d8d451
line wrap: on
line diff
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -6006,6 +6006,7 @@ mch_expand_wildcards(
 {
     int		i;
     size_t	len;
+    long	llen;
     char_u	*p;
     int		dir;
 
@@ -6292,9 +6293,13 @@ mch_expand_wildcards(
 	goto notfound;
     }
     fseek(fd, 0L, SEEK_END);
-    len = ftell(fd);			/* get size of temp file */
+    llen = ftell(fd);			/* get size of temp file */
     fseek(fd, 0L, SEEK_SET);
-    buffer = alloc(len + 1);
+    if (llen < 0)
+	/* just in case ftell() would fail */
+	buffer = NULL;
+    else
+	buffer = alloc(llen + 1);
     if (buffer == NULL)
     {
 	/* out of memory */
@@ -6303,6 +6308,7 @@ mch_expand_wildcards(
 	fclose(fd);
 	return FAIL;
     }
+    len = llen;
     i = fread((char *)buffer, 1, len, fd);
     fclose(fd);
     mch_remove(tempname);