Avoid integer overflow when LIMIT + OFFSET >= 2^63.
authorHeikki Linnakangas <[email protected]>
Tue, 2 Aug 2011 07:47:17 +0000 (10:47 +0300)
committerHeikki Linnakangas <[email protected]>
Tue, 2 Aug 2011 08:31:15 +0000 (11:31 +0300)
This fixes bug #6139 reported by Hitoshi Harada.

src/backend/executor/nodeLimit.c

index 0626b8be3718864b2cf0216b68361a73d6e1fc85..d002848bd32783fb8591ad7ac4a1b576473ea9d5 100644 (file)
@@ -125,7 +125,7 @@ ExecLimit(LimitState *node)
                 * the state machine state to record having done so.
                 */
                if (!node->noCount &&
-                   node->position >= node->offset + node->count)
+                   node->position - node->offset >= node->count)
                {
                    node->lstate = LIMIT_WINDOWEND;
                    return NULL;