정수 오버플로로 생성 된 잘못된 숫자를 수정하려면 어떻게해야합니까?

정수 오버플로를 일으키는 버그가있어서 데이터베이스에 잘못된 (음의) 타임 스탬프가 기록되었습니다. 코드 는 이미 수정되었지만 잘못된 데이터 도 수정하고 싶습니다 .

잘못된 결과를 가져 와서 추가 할 수 있다고 생각했습니다. Integer.MAX_VALUE,하지만 작동하지 않는 것 같았으며 높은 값을 남겼습니다.아래 코드 스 니펫에 offset 값이 있지만 입력 값이 저장되지 않습니다.

다음 코드는 버그를 재현합니다.

@Test
public void testArexxConversion()
{
    // The input values represent seconds since midnight, Jan 1, 2000 UTC
    final int sample = 361450072; // A sample input value drawn from production
    // I use the offset from the UNIX epoch to convert the vakue to UNIX seconds
    final int offset = 946684800; // midnight, Jan 01 2000 UTC in UNIX seconds
    // This was the buggy line in my code, the assertion will fail
    long result = (sample + offset) * 1000;
    // Prints 'Result is negative: -1830153280'
    Assert.assertTrue(result > 0, String.format("Result is negative: %d", result));
    // This is for comparison
    Date dt = new Date(offset * 1000);
    Assert.assertEquals(dt.getTime() + sample * 1000, result);
}
7
задан Hanno Fietz 15 June 2011 в 11:36
поделиться