This project has moved and is read-only. For the latest updates, please go here.

Weird malloc?

Aug 25, 2011 at 8:34 PM

At line 664 there is this allocation:

 hMods = (HMODULE*) malloc(sizeof(HMODULE) * (TTBUFLEN / sizeof HMODULE));

Just tried to compile it with gcc and it complained about the missing '()' around the last 'HMODULE'. 

The expression as it stands is "A * (X / A)". Which I learned in math-class is the same as "A". Why the complexity? 


 --gv

Jun 13, 2013 at 3:14 PM
old post.. but if anyone will need an answer -
Since this is integer division A(X/A) != X
This was done so the allocated memory will always be divisible by sizeof(HMODULE).
So if sizeof(HMODULE) is 4, and TTBUFLEN is 9, the resulting allocated memory will still be 8=4
2.
Sep 14, 2014 at 8:21 PM
sizeof syntax corrected in main trunk
Marked as answer by jkalmbach on 9/15/2014 at 2:03 AM