Skip to content

Commit 3454192

Browse files
committed
libvisual/lv_bmp.c: Address warning -Wunused-result
Symptom was: > lv_bmp.c: In function 'visual_bitmap_load': > lv_bmp.c:286:9: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 286 | fread (magic, 2, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:294:9: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 294 | fread (&bf_size, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:301:9: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 301 | fread (&bf_bits, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:305:9: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 305 | fread (&bi_size, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:310:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 310 | fread (&bi_width, 2, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:311:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 311 | fread (&bi_height, 2, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:319:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 319 | fread (&bi_bitcount, 2, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:324:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 324 | fread (&bi_width, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:325:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 325 | fread (&bi_height, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:333:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 333 | fread (&bi_bitcount, 2, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:337:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 337 | fread (&bi_compression, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > lv_bmp.c:344:17: warning: ignoring return value of 'fread' declared with attribute 'warn_unused_result' [-Wunused-result] > 344 | fread (&bi_clrused, 4, 1, fp); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 parent b3c78cf commit 3454192

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

libvisual/libvisual/lv_bmp.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,65 +283,89 @@ int visual_bitmap_load (VisVideo *video, const char *filename)
283283
}
284284

285285
/* Read the magic string */
286-
fread (magic, 2, 1, fp);
286+
if (fread (magic, 2, 1, fp) != 1) {
287+
return -VISUAL_ERROR_BMP_NO_BMP;
288+
}
287289
if (strncmp (magic, "BM", 2) != 0) {
288290
visual_log (VISUAL_LOG_WARNING, _("Not a bitmap file"));
289291
fclose (fp);
290292
return -VISUAL_ERROR_BMP_NO_BMP;
291293
}
292294

293295
/* Read the file size */
294-
fread (&bf_size, 4, 1, fp);
296+
if (fread (&bf_size, 4, 1, fp) != 1) {
297+
return -VISUAL_ERROR_BMP_CORRUPTED;
298+
}
295299
bf_size = VISUAL_ENDIAN_LEI32 (bf_size);
296300

297301
/* Skip past the reserved bits */
298302
fseek (fp, 4, SEEK_CUR);
299303

300304
/* Read the offset bits */
301-
fread (&bf_bits, 4, 1, fp);
305+
if (fread (&bf_bits, 4, 1, fp) != 1) {
306+
return -VISUAL_ERROR_BMP_CORRUPTED;
307+
}
302308
bf_bits = VISUAL_ENDIAN_LEI32 (bf_bits);
303309

304310
/* Read the info structure size */
305-
fread (&bi_size, 4, 1, fp);
311+
if (fread (&bi_size, 4, 1, fp) != 1) {
312+
return -VISUAL_ERROR_BMP_CORRUPTED;
313+
}
306314
bi_size = VISUAL_ENDIAN_LEI32 (bi_size);
307315

308316
if (bi_size == 12) {
309317
/* And read the width, height */
310-
fread (&bi_width, 2, 1, fp);
311-
fread (&bi_height, 2, 1, fp);
318+
if (fread (&bi_width, 2, 1, fp) != 1) {
319+
return -VISUAL_ERROR_BMP_CORRUPTED;
320+
}
321+
if (fread (&bi_height, 2, 1, fp) != 1) {
322+
return -VISUAL_ERROR_BMP_CORRUPTED;
323+
}
312324
bi_width = VISUAL_ENDIAN_LEI16 (bi_width);
313325
bi_height = VISUAL_ENDIAN_LEI16 (bi_height);
314326

315327
/* Skip over the planet */
316328
fseek (fp, 2, SEEK_CUR);
317329

318330
/* Read the bits per pixel */
319-
fread (&bi_bitcount, 2, 1, fp);
331+
if (fread (&bi_bitcount, 2, 1, fp) != 1) {
332+
return -VISUAL_ERROR_BMP_CORRUPTED;
333+
}
320334
bi_bitcount = VISUAL_ENDIAN_LEI16 (bi_bitcount);
321335
bi_compression = BI_RGB;
322336
} else {
323337
/* And read the width, height */
324-
fread (&bi_width, 4, 1, fp);
325-
fread (&bi_height, 4, 1, fp);
338+
if (fread (&bi_width, 4, 1, fp) != 1) {
339+
return -VISUAL_ERROR_BMP_CORRUPTED;
340+
}
341+
if (fread (&bi_height, 4, 1, fp) != 1) {
342+
return -VISUAL_ERROR_BMP_CORRUPTED;
343+
}
326344
bi_width = VISUAL_ENDIAN_LEI32 (bi_width);
327345
bi_height = VISUAL_ENDIAN_LEI32 (bi_height);
328346

329347
/* Skip over the planet */
330348
fseek (fp, 2, SEEK_CUR);
331349

332350
/* Read the bits per pixel */
333-
fread (&bi_bitcount, 2, 1, fp);
351+
if (fread (&bi_bitcount, 2, 1, fp) != 1) {
352+
return -VISUAL_ERROR_BMP_CORRUPTED;
353+
}
334354
bi_bitcount = VISUAL_ENDIAN_LEI16 (bi_bitcount);
335355

336356
/* Read the compression flag */
337-
fread (&bi_compression, 4, 1, fp);
357+
if (fread (&bi_compression, 4, 1, fp) != 1) {
358+
return -VISUAL_ERROR_BMP_CORRUPTED;
359+
}
338360
bi_compression = VISUAL_ENDIAN_LEI32 (bi_compression);
339361

340362
/* Skip over the nonsense we don't want to know */
341363
fseek (fp, 12, SEEK_CUR);
342364

343365
/* Number of colors in palette */
344-
fread (&bi_clrused, 4, 1, fp);
366+
if (fread (&bi_clrused, 4, 1, fp) != 1) {
367+
return -VISUAL_ERROR_BMP_CORRUPTED;
368+
}
345369
bi_clrused = VISUAL_ENDIAN_LEI32 (bi_clrused);
346370

347371
/* Skip over the other nonsense */

0 commit comments

Comments
 (0)