fixed 32-bit overflow error (negative int)  for new segment offset by adding a check with error handling