the code is read as: int count_power_items_fast(int v) { int c = 0; while(v) { c += (v & 1); v >>= 1; }
return c; }
when v is negative, this function wont stop because, (-1 >> 1) -> -1 in arithmetic shift. the fix is probably too simple to warranty a patch: change int v to uint32_t v .