e688175
To: vim-dev@vim.org
e688175
Subject: Patch 7.2.050
e688175
Fcc: outbox
e688175
From: Bram Moolenaar <Bram@moolenaar.net>
e688175
Mime-Version: 1.0
e688175
Content-Type: text/plain; charset=ISO-8859-1
e688175
Content-Transfer-Encoding: 8bit
e688175
------------
e688175
e688175
Patch 7.2.050
e688175
Problem:    Warnings for not checking return value of fwrite(). (Chip Campbell)
e688175
Solution:   Use the return value.
e688175
Files:	    src/spell.c
e688175
e688175
e688175
*** ../vim-7.2.049/src/spell.c	Mon Aug 25 04:12:38 2008
e688175
--- src/spell.c	Thu Nov 20 17:28:01 2008
e688175
***************
e688175
*** 7926,7931 ****
e688175
--- 7926,7933 ----
e688175
      char_u	*p;
e688175
      int		rr;
e688175
      int		retval = OK;
e688175
+     int		fwv = 1;  /* collect return value of fwrite() to avoid
e688175
+ 			     warnings from picky compiler */
e688175
  
e688175
      fd = mch_fopen((char *)fname, "w");
e688175
      if (fd == NULL)
e688175
***************
e688175
*** 7936,7946 ****
e688175
  
e688175
      /* <HEADER>: <fileID> <versionnr> */
e688175
  							    /* <fileID> */
e688175
!     if (fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd) != 1)
e688175
!     {
e688175
! 	EMSG(_(e_write));
e688175
! 	retval = FAIL;
e688175
!     }
e688175
      putc(VIMSPELLVERSION, fd);				    /* <versionnr> */
e688175
  
e688175
      /*
e688175
--- 7938,7944 ----
e688175
  
e688175
      /* <HEADER>: <fileID> <versionnr> */
e688175
  							    /* <fileID> */
e688175
!     fwv &= fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd);
e688175
      putc(VIMSPELLVERSION, fd);				    /* <versionnr> */
e688175
  
e688175
      /*
e688175
***************
e688175
*** 7955,7961 ****
e688175
  
e688175
  	i = (int)STRLEN(spin->si_info);
e688175
  	put_bytes(fd, (long_u)i, 4);			/* <sectionlen> */
e688175
! 	fwrite(spin->si_info, (size_t)i, (size_t)1, fd); /* <infotext> */
e688175
      }
e688175
  
e688175
      /* SN_REGION: <regionname> ...
e688175
--- 7953,7959 ----
e688175
  
e688175
  	i = (int)STRLEN(spin->si_info);
e688175
  	put_bytes(fd, (long_u)i, 4);			/* <sectionlen> */
e688175
! 	fwv &= fwrite(spin->si_info, (size_t)i, (size_t)1, fd); /* <infotext> */
e688175
      }
e688175
  
e688175
      /* SN_REGION: <regionname> ...
e688175
***************
e688175
*** 7966,7972 ****
e688175
  	putc(SNF_REQUIRED, fd);				/* <sectionflags> */
e688175
  	l = spin->si_region_count * 2;
e688175
  	put_bytes(fd, (long_u)l, 4);			/* <sectionlen> */
e688175
! 	fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
e688175
  							/* <regionname> ... */
e688175
  	regionmask = (1 << spin->si_region_count) - 1;
e688175
      }
e688175
--- 7964,7970 ----
e688175
  	putc(SNF_REQUIRED, fd);				/* <sectionflags> */
e688175
  	l = spin->si_region_count * 2;
e688175
  	put_bytes(fd, (long_u)l, 4);			/* <sectionlen> */
e688175
! 	fwv &= fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
e688175
  							/* <regionname> ... */
e688175
  	regionmask = (1 << spin->si_region_count) - 1;
e688175
      }
e688175
***************
e688175
*** 8016,8022 ****
e688175
  	}
e688175
  
e688175
  	put_bytes(fd, (long_u)l, 2);			/* <folcharslen> */
e688175
! 	fwrite(folchars, (size_t)l, (size_t)1, fd);	/* <folchars> */
e688175
      }
e688175
  
e688175
      /* SN_MIDWORD: <midword> */
e688175
--- 8014,8020 ----
e688175
  	}
e688175
  
e688175
  	put_bytes(fd, (long_u)l, 2);			/* <folcharslen> */
e688175
! 	fwv &= fwrite(folchars, (size_t)l, (size_t)1, fd); /* <folchars> */
e688175
      }
e688175
  
e688175
      /* SN_MIDWORD: <midword> */
e688175
***************
e688175
*** 8027,8033 ****
e688175
  
e688175
  	i = (int)STRLEN(spin->si_midword);
e688175
  	put_bytes(fd, (long_u)i, 4);			/* <sectionlen> */
e688175
! 	fwrite(spin->si_midword, (size_t)i, (size_t)1, fd); /* <midword> */
e688175
      }
e688175
  
e688175
      /* SN_PREFCOND: <prefcondcnt> <prefcond> ... */
e688175
--- 8025,8032 ----
e688175
  
e688175
  	i = (int)STRLEN(spin->si_midword);
e688175
  	put_bytes(fd, (long_u)i, 4);			/* <sectionlen> */
e688175
! 	fwv &= fwrite(spin->si_midword, (size_t)i, (size_t)1, fd);
e688175
! 							/* <midword> */
e688175
      }
e688175
  
e688175
      /* SN_PREFCOND: <prefcondcnt> <prefcond> ... */
e688175
***************
e688175
*** 8113,8119 ****
e688175
  		p = rr == 1 ? ftp->ft_from : ftp->ft_to;
e688175
  		l = (int)STRLEN(p);
e688175
  		putc(l, fd);
e688175
! 		fwrite(p, l, (size_t)1, fd);
e688175
  	    }
e688175
  	}
e688175
  
e688175
--- 8112,8118 ----
e688175
  		p = rr == 1 ? ftp->ft_from : ftp->ft_to;
e688175
  		l = (int)STRLEN(p);
e688175
  		putc(l, fd);
e688175
! 		fwv &= fwrite(p, l, (size_t)1, fd);
e688175
  	    }
e688175
  	}
e688175
  
e688175
***************
e688175
*** 8131,8141 ****
e688175
  							/* <sectionlen> */
e688175
  
e688175
  	put_bytes(fd, (long_u)l, 2);			/* <sofofromlen> */
e688175
! 	fwrite(spin->si_sofofr, l, (size_t)1, fd);	/* <sofofrom> */
e688175
  
e688175
  	l = (int)STRLEN(spin->si_sofoto);
e688175
  	put_bytes(fd, (long_u)l, 2);			/* <sofotolen> */
e688175
! 	fwrite(spin->si_sofoto, l, (size_t)1, fd);	/* <sofoto> */
e688175
      }
e688175
  
e688175
      /* SN_WORDS: <word> ...
e688175
--- 8130,8140 ----
e688175
  							/* <sectionlen> */
e688175
  
e688175
  	put_bytes(fd, (long_u)l, 2);			/* <sofofromlen> */
e688175
! 	fwv &= fwrite(spin->si_sofofr, l, (size_t)1, fd); /* <sofofrom> */
e688175
  
e688175
  	l = (int)STRLEN(spin->si_sofoto);
e688175
  	put_bytes(fd, (long_u)l, 2);			/* <sofotolen> */
e688175
! 	fwv &= fwrite(spin->si_sofoto, l, (size_t)1, fd); /* <sofoto> */
e688175
      }
e688175
  
e688175
      /* SN_WORDS: <word> ...
e688175
***************
e688175
*** 8160,8166 ****
e688175
  		    l = (int)STRLEN(hi->hi_key) + 1;
e688175
  		    len += l;
e688175
  		    if (round == 2)			/* <word> */
e688175
! 			fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
e688175
  		    --todo;
e688175
  		}
e688175
  	    if (round == 1)
e688175
--- 8159,8165 ----
e688175
  		    l = (int)STRLEN(hi->hi_key) + 1;
e688175
  		    len += l;
e688175
  		    if (round == 2)			/* <word> */
e688175
! 			fwv &= fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
e688175
  		    --todo;
e688175
  		}
e688175
  	    if (round == 1)
e688175
***************
e688175
*** 8176,8182 ****
e688175
  	putc(0, fd);					/* <sectionflags> */
e688175
  	l = spin->si_map.ga_len;
e688175
  	put_bytes(fd, (long_u)l, 4);			/* <sectionlen> */
e688175
! 	fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
e688175
  							/* <mapstr> */
e688175
      }
e688175
  
e688175
--- 8175,8181 ----
e688175
  	putc(0, fd);					/* <sectionflags> */
e688175
  	l = spin->si_map.ga_len;
e688175
  	put_bytes(fd, (long_u)l, 4);			/* <sectionlen> */
e688175
! 	fwv &= fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
e688175
  							/* <mapstr> */
e688175
      }
e688175
  
e688175
***************
e688175
*** 8232,8241 ****
e688175
  	{
e688175
  	    p = ((char_u **)(spin->si_comppat.ga_data))[i];
e688175
  	    putc((int)STRLEN(p), fd);			/* <comppatlen> */
e688175
! 	    fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);/* <comppattext> */
e688175
  	}
e688175
  							/* <compflags> */
e688175
! 	fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
e688175
  							       (size_t)1, fd);
e688175
      }
e688175
  
e688175
--- 8231,8241 ----
e688175
  	{
e688175
  	    p = ((char_u **)(spin->si_comppat.ga_data))[i];
e688175
  	    putc((int)STRLEN(p), fd);			/* <comppatlen> */
e688175
! 	    fwv &= fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);
e688175
! 							/* <comppattext> */
e688175
  	}
e688175
  							/* <compflags> */
e688175
! 	fwv &= fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
e688175
  							       (size_t)1, fd);
e688175
      }
e688175
  
e688175
***************
e688175
*** 8259,8265 ****
e688175
  
e688175
  	l = (int)STRLEN(spin->si_syllable);
e688175
  	put_bytes(fd, (long_u)l, 4);			/* <sectionlen> */
e688175
! 	fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd); /* <syllable> */
e688175
      }
e688175
  
e688175
      /* end of <SECTIONS> */
e688175
--- 8259,8266 ----
e688175
  
e688175
  	l = (int)STRLEN(spin->si_syllable);
e688175
  	put_bytes(fd, (long_u)l, 4);			/* <sectionlen> */
e688175
! 	fwv &= fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd);
e688175
! 							/* <syllable> */
e688175
      }
e688175
  
e688175
      /* end of <SECTIONS> */
e688175
***************
e688175
*** 8295,8307 ****
e688175
  	(void)put_node(fd, tree, 0, regionmask, round == 3);
e688175
      }
e688175
  
e688175
!     /* Write another byte to check for errors. */
e688175
      if (putc(0, fd) == EOF)
e688175
  	retval = FAIL;
e688175
  
e688175
      if (fclose(fd) == EOF)
e688175
  	retval = FAIL;
e688175
  
e688175
      return retval;
e688175
  }
e688175
  
e688175
--- 8296,8313 ----
e688175
  	(void)put_node(fd, tree, 0, regionmask, round == 3);
e688175
      }
e688175
  
e688175
!     /* Write another byte to check for errors (file system full). */
e688175
      if (putc(0, fd) == EOF)
e688175
  	retval = FAIL;
e688175
  
e688175
      if (fclose(fd) == EOF)
e688175
  	retval = FAIL;
e688175
  
e688175
+     if (fwv != 1)
e688175
+ 	retval = FAIL;
e688175
+     if (retval == FAIL)
e688175
+ 	EMSG(_(e_write));
e688175
+ 
e688175
      return retval;
e688175
  }
e688175
  
e688175
***************
e688175
*** 9890,9895 ****
e688175
--- 9896,9902 ----
e688175
      char_u	*p;
e688175
      int		len;
e688175
      int		totlen;
e688175
+     int		x = 1;  /* collect return value of fwrite() */
e688175
  
e688175
      if (fd != NULL)
e688175
  	put_bytes(fd, (long_u)gap->ga_len, 2);	    /* <prefcondcnt> */
e688175
***************
e688175
*** 9906,9912 ****
e688175
  	    if (fd != NULL)
e688175
  	    {
e688175
  		fputc(len, fd);
e688175
! 		fwrite(p, (size_t)len, (size_t)1, fd);
e688175
  	    }
e688175
  	    totlen += len;
e688175
  	}
e688175
--- 9913,9919 ----
e688175
  	    if (fd != NULL)
e688175
  	    {
e688175
  		fputc(len, fd);
e688175
! 		x &= fwrite(p, (size_t)len, (size_t)1, fd);
e688175
  	    }
e688175
  	    totlen += len;
e688175
  	}
e688175
*** ../vim-7.2.049/src/version.c	Thu Nov 20 17:09:09 2008
e688175
--- src/version.c	Fri Nov 28 10:06:13 2008
e688175
***************
e688175
*** 678,679 ****
e688175
--- 678,681 ----
e688175
  {   /* Add new patch number below this line */
e688175
+ /**/
e688175
+     50,
e688175
  /**/
e688175
e688175
-- 
e688175
You got to work at a mill?  Lucky!  I got sent back to work in the
e688175
acid-mines for my daily crust of stale bread... which not even the
e688175
birds would eat.
e688175
e688175
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
e688175
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
e688175
\\\        download, build and distribute -- http://www.A-A-P.org        ///
e688175
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///