Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix datatype confusion in logtape.c's right_offset().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Dec 2021 16:46:36 +0000 (11:46 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Dec 2021 16:46:44 +0000 (11:46 -0500)
This could only matter if (a) long is wider than int, and (b) the heap
of free blocks exceeds UINT_MAX entries, which seems pretty unlikely.
Still, it's a theoretical bug, so backpatch to v13 where the typo came
in (in commit c02fdc922).

In passing, also make swap_nodes() use consistent datatypes.

Ma Liangzhu

Discussion: https://postgr.es/m/17336-fc4e522d26a750fd@postgresql.org

src/backend/utils/sort/logtape.c

index cafc087254906934197a9fe2ef6c8f4e25c3a7b0..b97414c7518b35236b7f5321b8452ea6c9a63aa1 100644 (file)
@@ -345,7 +345,7 @@ ltsReadFillBuffer(LogicalTapeSet *lts, LogicalTape *lt)
 static inline void
 swap_nodes(long *heap, unsigned long a, unsigned long b)
 {
-   unsigned long swap;
+   long        swap;
 
    swap = heap[a];
    heap[a] = heap[b];
@@ -359,7 +359,7 @@ left_offset(unsigned long i)
 }
 
 static inline unsigned long
-right_offset(unsigned i)
+right_offset(unsigned long i)
 {
    return 2 * i + 2;
 }