Bug Summary

File:src/stdio/fread.c
Location:line 30, column 18
Description:Division by zero

Annotated Source Code

1#include "stdio_impl.h"
2#include <string.h>
3
4#define MIN(a,b)((a)<(b) ? (a) : (b)) ((a)<(b) ? (a) : (b))
5
6size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
7{
8 unsigned char *dest = destv;
9 size_t len = size*nmemb, l = len, k;
10 if (!size) nmemb = 0;
1
Assuming 'size' is 0
2
Taking true branch
11
12 FLOCK(f)int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0
)
;
13
14 f->mode |= f->mode-1;
15
16 if (f->rend - f->rpos > 0) {
3
Taking false branch
17 /* First exhaust the buffer. */
18 k = MIN(f->rend - f->rpos, l)((f->rend - f->rpos)<(l) ? (f->rend - f->rpos)
: (l))
;
19 memcpy(dest, f->rpos, k);
20 f->rpos += k;
21 dest += k;
22 l -= k;
23 }
24
25 /* Read the remainder directly */
26 for (; l; l-=k, dest+=k) {
4
Loop condition is true. Entering loop body
27 k = __toread(f) ? 0 : f->read(f, dest, l);
5
'?' condition is true
28 if (k+1<=1) {
6
Taking true branch
29 FUNLOCK(f)if (__need_unlock) __unlockfile((f)); else;
30 return (len-l)/size;
7
Division by zero
31 }
32 }
33
34 FUNLOCK(f)if (__need_unlock) __unlockfile((f)); else;
35 return nmemb;
36}
37
38weak_alias(fread, fread_unlocked)extern __typeof(fread) fread_unlocked __attribute__((weak, alias
("fread")))
;