comparison 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
comparison
equal deleted inserted replaced
11280:f8690bedf784 11281:2e6a0ea76a0d
6004 char_u ***file, 6004 char_u ***file,
6005 int flags) /* EW_* flags */ 6005 int flags) /* EW_* flags */
6006 { 6006 {
6007 int i; 6007 int i;
6008 size_t len; 6008 size_t len;
6009 long llen;
6009 char_u *p; 6010 char_u *p;
6010 int dir; 6011 int dir;
6011 6012
6012 /* 6013 /*
6013 * This is the non-OS/2 implementation (really Unix). 6014 * This is the non-OS/2 implementation (really Unix).
6290 } 6291 }
6291 vim_free(tempname); 6292 vim_free(tempname);
6292 goto notfound; 6293 goto notfound;
6293 } 6294 }
6294 fseek(fd, 0L, SEEK_END); 6295 fseek(fd, 0L, SEEK_END);
6295 len = ftell(fd); /* get size of temp file */ 6296 llen = ftell(fd); /* get size of temp file */
6296 fseek(fd, 0L, SEEK_SET); 6297 fseek(fd, 0L, SEEK_SET);
6297 buffer = alloc(len + 1); 6298 if (llen < 0)
6299 /* just in case ftell() would fail */
6300 buffer = NULL;
6301 else
6302 buffer = alloc(llen + 1);
6298 if (buffer == NULL) 6303 if (buffer == NULL)
6299 { 6304 {
6300 /* out of memory */ 6305 /* out of memory */
6301 mch_remove(tempname); 6306 mch_remove(tempname);
6302 vim_free(tempname); 6307 vim_free(tempname);
6303 fclose(fd); 6308 fclose(fd);
6304 return FAIL; 6309 return FAIL;
6305 } 6310 }
6311 len = llen;
6306 i = fread((char *)buffer, 1, len, fd); 6312 i = fread((char *)buffer, 1, len, fd);
6307 fclose(fd); 6313 fclose(fd);
6308 mch_remove(tempname); 6314 mch_remove(tempname);
6309 if (i != (int)len) 6315 if (i != (int)len)
6310 { 6316 {