int ScaleAndRound(int value, double scaling) {
  return static_cast<int>(static_cast<double>(value) / scaling);
}

The product writes data past the end, or before the beginning, of the intended buffer.