From 1378d9c58b05f2f45352df155463ab8cd55276a6 Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 12 Dec 2019 16:21:51 -0500 Subject: [PATCH] Fix bad arithmetic in pgLsnToWalSegment(). / takes precedence over & but the appropriate parens were not provided. By some bad luck the tests worked either way, so add a new test that only works the correct way to prevent a regression. --- src/postgres/interface.c | 2 +- test/src/module/postgres/interfaceTest.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/postgres/interface.c b/src/postgres/interface.c index 4b33252e4..52f91977f 100644 --- a/src/postgres/interface.c +++ b/src/postgres/interface.c @@ -619,7 +619,7 @@ pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize) FUNCTION_TEST_END(); FUNCTION_TEST_RETURN( - strNewFmt("%08X%08X%08X", timeline, (unsigned int)(lsn >> 32), (unsigned int)(lsn & 0xFFFFFFFF / walSegmentSize))); + strNewFmt("%08X%08X%08X", timeline, (unsigned int)(lsn >> 32), (unsigned int)(lsn & 0xFFFFFFFF) / walSegmentSize)); } /**********************************************************************************************************************************/ diff --git a/test/src/module/postgres/interfaceTest.c b/test/src/module/postgres/interfaceTest.c index a421491a3..6e0dfa907 100644 --- a/test/src/module/postgres/interfaceTest.c +++ b/test/src/module/postgres/interfaceTest.c @@ -114,6 +114,7 @@ testRun(void) TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFFAAAAAAAA, 0x1000000), "00000001FFFFFFFF000000AA", "lsn to wal segment"); TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFFAAAAAAAA, 0x40000000), "00000001FFFFFFFF00000002", "lsn to wal segment"); + TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFF40000000, 0x40000000), "00000001FFFFFFFF00000001", "lsn to wal segment"); } // *****************************************************************************************************************************