Skip to content
  • Martin Nolte's avatar
    also fix pointer arithmetic in the copy constructor · 60c1d035
    Martin Nolte authored
    The problem with the old implementation was this:
    diff = (coeff_ - other.coeff_) is a difference between pointers of type Field *.
    Therefore, this difference includes an integer division (by sizeof( Field )).
    If the pointers were not aligned on sizeof( Field ) boundary, rounding occurs.
    Next thing other.rows_[ i ] + diff results in remultiplying with this size, bout
    the roundoff error persists and might, hence, lead to a segmentation fault.
    
    The solution was easy: use (other.rows_[ i ] - other.coeff_) for the difference.
    Since other.rows_[ i ] = k * sizeof( Field ) + other.coeff_ for some k, this division
    is safe.
    
    [[Imported from SVN: r873]]
    60c1d035