I hope I'm not splitting hairs here, but as I was going through the code
for '
/dev/random<https://android.googlesource.com/kernel/msm.git/+/eaf36994a3992b8f918c18e4f7411e8b2320a35f/drivers/char/random.c>
'
(in this instance), I noticed that ' unsigned long ' is being used in lieu
of, say, ' size_t '. For example, in the following code --
1. unsigned long
2. randomize_range(unsigned long start, unsigned long end, unsigned longlen
)
3. {
4. unsigned long range = end - len - start;
5.
6. if (end <= start + len)
7. return 0;
8. return PAGE_ALIGN(get_random_int() % range + start);
9. }
-- would it not be more practical to use size_t as the type conveys
context better (though, I admit this is subjective) ? On another note,
since get_random_int() returns 'unsigned int' and the PAGE_ALIGN macro uses
typeof() I know there is at least one explicit casting done via PAGE_ALIGN,
but I am unsure as to why get_random_int() itself is not being explicitly
casted.
This, I think, is the way it makes most sense to me:
size_t
randomize_range(size_t start, size_t end, size_t len)
{
size_t range = end - len - start;
if (end <= start + len)
return 0;
return PAGE_ALIGN((((size_t)get_random_int()) % range) + start);
}
Am I gravely mistaken? I'm no expert by any means, so any insight would be
much appreciated. Thanks.
--
unsubscribe: [email protected]
website: http://groups.google.com/group/android-kernel