3 ms·
Here you don't check the return value of calloc(): https://github.com/AndrewBelt/bored/blob/master/src/map.c#L33 https://github.com/AndrewBelt/bored/blob/maste
by dchest 10y ago
Here you don't check the return value of calloc():
https://github.com/AndrewBelt/bored/blob/master/src/map.c#L33 https://github.com/AndrewBelt/bored/blob/master/src/map.c#L3...
and then access it:
https://github.com/AndrewBelt/bored/blob/master/src/map.c#L44 https://github.com/AndrewBelt/bored/blob/master/src/map.c#L4...
Here if realloc() fails, you'll have a memory leak and, again, accessing NULL later:
https://github.com/AndrewBelt/bored/blob/master/src/priq.c#L28 https://github.com/AndrewBelt/bored/blob/master/src/priq.c#L...
There is also integer overflow: alloc is int, so if it becomes greater than 2^31-1, it may wrap around [I think signed int behaviour in C is undefined in this case], and you'll allocate fewer bytes than needed, leading to buffer overflow.
- dmytroi 10y agoWell, to be honest, very few programs are able to orchestrate >2GB allocations correctly when complied to 32 bit binary, like Visual Studio linker is not aware of >2GB sizes by default (one need to /LARGEADDRESSAWARE flag for it), which was a trouble for modern browsers because linker was unable to fit everything in limited virtual address space. And another to be honest, very few programs on desktops/mobile are actually checking return values of malloc/calloc, because of amount of data that program operates is usually much smaller than amount of RAM available. It's sure a case for embedded, but you simply usually don't use malloc for embedded.