JohnLangford/vowpal_wabbit — pull request #348 by qiaomuf (2014-07-24 04:29:03+00:00)
Title: Fix float point overflow when doing pass up

The old way of rounding floor(x/((float)sizeof(int)))*sizeof(int)) will
cause overflow when x is greater than 203672784. For example, if x is
203672800, the above expression will give 203672792. When it's minus by
parent_sent_pos, negative value can be generated which is later passed
to an unsigned integer. This will cause the whole learning fail. This
patch fixes the above expression and a potential network problem.

A simple program can reproduce the problem:
#include
#include
#include
#include

int main()
{
int64_t x = 203672784;
for(int64_t x = 203672784; ; ++x)
{
if ((int)(floor(x/((float)sizeof(int)))*sizeof(int)) > x)
{
std::cout << ((int)(floor(x/((float)sizeof(int)))*sizeof(int))) << " " << x << std::endl;
break;
}
}
}