[PATCH] work_mem calculation possible overflow

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] work_mem calculation possible overflow
Date: 2013-12-28 06:31:34
Message-ID: CAApHDvqMg=1tYjeQBFiRadRotp0L3ZCM2RzPXQ9xF8yFKF8oSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I was just looking through a few of the warnings flagged up by PVS Studio.
I found some warnings around some calculations that were doing work_mem *
1024L and comparing that to a double. On windows 64 sizeof(long) is 4 bytes.
Currently work_mem's maximum value is INT_MAX / 1024, so this should not
overflow on windows 64 at the moment, but perhaps if work_mem's maximum is
raised in the future then it will. In any case the L suffix on 1024 to
widen the type here just seems a bit wrong giving that postgresql supports
platforms where sizeof(int) and sizeof(long) is the same.

Its very possible that there are more pressing things to fix from the PVS
Studio's list, but I thought I'd have a go at doing a bit of weeding and
try reducing the list a bit.

Patch attached.

Regards

David Rowley

Attachment Content-Type Size
work_mem_overflow.patch application/octet-stream 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message MauMau 2013-12-28 07:37:44 Re: [bug fix] connection service file doesn't take effect with ECPG apps
Previous Message Stephen Frost 2013-12-28 02:24:44 Re: preserving forensic information when we freeze