1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
To: vim-dev@vim.org
Subject: Patch 7.2.050
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------
Patch 7.2.050
Problem: Warnings for not checking return value of fwrite(). (Chip Campbell)
Solution: Use the return value.
Files: src/spell.c
*** ../vim-7.2.049/src/spell.c Mon Aug 25 04:12:38 2008
--- src/spell.c Thu Nov 20 17:28:01 2008
***************
*** 7926,7931 ****
--- 7926,7933 ----
char_u *p;
int rr;
int retval = OK;
+ int fwv = 1; /* collect return value of fwrite() to avoid
+ warnings from picky compiler */
fd = mch_fopen((char *)fname, "w");
if (fd == NULL)
***************
*** 7936,7946 ****
/* <HEADER>: <fileID> <versionnr> */
/* <fileID> */
! if (fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd) != 1)
! {
! EMSG(_(e_write));
! retval = FAIL;
! }
putc(VIMSPELLVERSION, fd); /* <versionnr> */
/*
--- 7938,7944 ----
/* <HEADER>: <fileID> <versionnr> */
/* <fileID> */
! fwv &= fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd);
putc(VIMSPELLVERSION, fd); /* <versionnr> */
/*
***************
*** 7955,7961 ****
i = (int)STRLEN(spin->si_info);
put_bytes(fd, (long_u)i, 4); /* <sectionlen> */
! fwrite(spin->si_info, (size_t)i, (size_t)1, fd); /* <infotext> */
}
/* SN_REGION: <regionname> ...
--- 7953,7959 ----
i = (int)STRLEN(spin->si_info);
put_bytes(fd, (long_u)i, 4); /* <sectionlen> */
! fwv &= fwrite(spin->si_info, (size_t)i, (size_t)1, fd); /* <infotext> */
}
/* SN_REGION: <regionname> ...
***************
*** 7966,7972 ****
putc(SNF_REQUIRED, fd); /* <sectionflags> */
l = spin->si_region_count * 2;
put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
! fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
/* <regionname> ... */
regionmask = (1 << spin->si_region_count) - 1;
}
--- 7964,7970 ----
putc(SNF_REQUIRED, fd); /* <sectionflags> */
l = spin->si_region_count * 2;
put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
! fwv &= fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
/* <regionname> ... */
regionmask = (1 << spin->si_region_count) - 1;
}
***************
*** 8016,8022 ****
}
put_bytes(fd, (long_u)l, 2); /* <folcharslen> */
! fwrite(folchars, (size_t)l, (size_t)1, fd); /* <folchars> */
}
/* SN_MIDWORD: <midword> */
--- 8014,8020 ----
}
put_bytes(fd, (long_u)l, 2); /* <folcharslen> */
! fwv &= fwrite(folchars, (size_t)l, (size_t)1, fd); /* <folchars> */
}
/* SN_MIDWORD: <midword> */
***************
*** 8027,8033 ****
i = (int)STRLEN(spin->si_midword);
put_bytes(fd, (long_u)i, 4); /* <sectionlen> */
! fwrite(spin->si_midword, (size_t)i, (size_t)1, fd); /* <midword> */
}
/* SN_PREFCOND: <prefcondcnt> <prefcond> ... */
--- 8025,8032 ----
i = (int)STRLEN(spin->si_midword);
put_bytes(fd, (long_u)i, 4); /* <sectionlen> */
! fwv &= fwrite(spin->si_midword, (size_t)i, (size_t)1, fd);
! /* <midword> */
}
/* SN_PREFCOND: <prefcondcnt> <prefcond> ... */
***************
*** 8113,8119 ****
p = rr == 1 ? ftp->ft_from : ftp->ft_to;
l = (int)STRLEN(p);
putc(l, fd);
! fwrite(p, l, (size_t)1, fd);
}
}
--- 8112,8118 ----
p = rr == 1 ? ftp->ft_from : ftp->ft_to;
l = (int)STRLEN(p);
putc(l, fd);
! fwv &= fwrite(p, l, (size_t)1, fd);
}
}
***************
*** 8131,8141 ****
/* <sectionlen> */
put_bytes(fd, (long_u)l, 2); /* <sofofromlen> */
! fwrite(spin->si_sofofr, l, (size_t)1, fd); /* <sofofrom> */
l = (int)STRLEN(spin->si_sofoto);
put_bytes(fd, (long_u)l, 2); /* <sofotolen> */
! fwrite(spin->si_sofoto, l, (size_t)1, fd); /* <sofoto> */
}
/* SN_WORDS: <word> ...
--- 8130,8140 ----
/* <sectionlen> */
put_bytes(fd, (long_u)l, 2); /* <sofofromlen> */
! fwv &= fwrite(spin->si_sofofr, l, (size_t)1, fd); /* <sofofrom> */
l = (int)STRLEN(spin->si_sofoto);
put_bytes(fd, (long_u)l, 2); /* <sofotolen> */
! fwv &= fwrite(spin->si_sofoto, l, (size_t)1, fd); /* <sofoto> */
}
/* SN_WORDS: <word> ...
***************
*** 8160,8166 ****
l = (int)STRLEN(hi->hi_key) + 1;
len += l;
if (round == 2) /* <word> */
! fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
--todo;
}
if (round == 1)
--- 8159,8165 ----
l = (int)STRLEN(hi->hi_key) + 1;
len += l;
if (round == 2) /* <word> */
! fwv &= fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
--todo;
}
if (round == 1)
***************
*** 8176,8182 ****
putc(0, fd); /* <sectionflags> */
l = spin->si_map.ga_len;
put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
! fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
/* <mapstr> */
}
--- 8175,8181 ----
putc(0, fd); /* <sectionflags> */
l = spin->si_map.ga_len;
put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
! fwv &= fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
/* <mapstr> */
}
***************
*** 8232,8241 ****
{
p = ((char_u **)(spin->si_comppat.ga_data))[i];
putc((int)STRLEN(p), fd); /* <comppatlen> */
! fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);/* <comppattext> */
}
/* <compflags> */
! fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
(size_t)1, fd);
}
--- 8231,8241 ----
{
p = ((char_u **)(spin->si_comppat.ga_data))[i];
putc((int)STRLEN(p), fd); /* <comppatlen> */
! fwv &= fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);
! /* <comppattext> */
}
/* <compflags> */
! fwv &= fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
(size_t)1, fd);
}
***************
*** 8259,8265 ****
l = (int)STRLEN(spin->si_syllable);
put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
! fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd); /* <syllable> */
}
/* end of <SECTIONS> */
--- 8259,8266 ----
l = (int)STRLEN(spin->si_syllable);
put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
! fwv &= fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd);
! /* <syllable> */
}
/* end of <SECTIONS> */
***************
*** 8295,8307 ****
(void)put_node(fd, tree, 0, regionmask, round == 3);
}
! /* Write another byte to check for errors. */
if (putc(0, fd) == EOF)
retval = FAIL;
if (fclose(fd) == EOF)
retval = FAIL;
return retval;
}
--- 8296,8313 ----
(void)put_node(fd, tree, 0, regionmask, round == 3);
}
! /* Write another byte to check for errors (file system full). */
if (putc(0, fd) == EOF)
retval = FAIL;
if (fclose(fd) == EOF)
retval = FAIL;
+ if (fwv != 1)
+ retval = FAIL;
+ if (retval == FAIL)
+ EMSG(_(e_write));
+
return retval;
}
***************
*** 9890,9895 ****
--- 9896,9902 ----
char_u *p;
int len;
int totlen;
+ int x = 1; /* collect return value of fwrite() */
if (fd != NULL)
put_bytes(fd, (long_u)gap->ga_len, 2); /* <prefcondcnt> */
***************
*** 9906,9912 ****
if (fd != NULL)
{
fputc(len, fd);
! fwrite(p, (size_t)len, (size_t)1, fd);
}
totlen += len;
}
--- 9913,9919 ----
if (fd != NULL)
{
fputc(len, fd);
! x &= fwrite(p, (size_t)len, (size_t)1, fd);
}
totlen += len;
}
*** ../vim-7.2.049/src/version.c Thu Nov 20 17:09:09 2008
--- src/version.c Fri Nov 28 10:06:13 2008
***************
*** 678,679 ****
--- 678,681 ----
{ /* Add new patch number below this line */
+ /**/
+ 50,
/**/
--
You got to work at a mill? Lucky! I got sent back to work in the
acid-mines for my daily crust of stale bread... which not even the
birds would eat.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|