Move allocation size overflow handling to MemoryContextAllocExtended()?

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Move allocation size overflow handling to MemoryContextAllocExtended()?
Дата
Msg-id 20161004235631.omnab3nvdpbirn4i@alap3.anarazel.de
обсуждение исходный текст
Ответы Re: Move allocation size overflow handling to MemoryContextAllocExtended()?  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-hackers
Hi,

I was working on making sure that allocations for [1] don't overflow
size_t for large hash tables, when created on 32bit systems.  I started
to write code like

if (sizeof(SH_CONTAINS) * (uint64) tb->size) !=  sizeof(SH_CONTAINS) * (size_t) tb->size))
{   elog(ERROR, "hash table too large for a 32 bit system");
}

that could code potentially, although somewhat unlikely, be trigger on a
32bit system.


That made me wonder if it's not actually a mistake for
MemoryContextAllocExtended() size parameter to be declared
Size/size_t. That prevents it from detecting such overflows, forcing
code like the above on callsites.

Comments?

- Andres

[1] http://archives.postgresql.org/message-id/20160727004333.r3e2k2y6fvk2ntup%40alap3.anarazel.de



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thomas Munro
Дата:
Сообщение: Re: Hash tables in dynamic shared memory
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Move allocation size overflow handling to MemoryContextAllocExtended()?