Fix condition in shm_toc and remove unused function shm_toc_freespace. - Mailing list pgsql-hackers

From Zhang Mingli
Subject Fix condition in shm_toc and remove unused function shm_toc_freespace.
Date
Msg-id 1c7954e4-1705-4855-a99d-c77bf426c3e7@Spark
Whole thread Raw
Responses Re: Fix condition in shm_toc and remove unused function shm_toc_freespace.
List pgsql-hackers
Hi, hackers

Some conditions in shm_toc_insert and shm_toc_allocate are bogus, like:

if (toc_bytes + nbytes > total_bytes || toc_bytes + nbytes < toc_bytes)

Remove the condition `toc_bytes + nbytes < toc_bytes` and take a sizeof(shm_entry) into account in shm_toc_allocate though 
shm_toc_allocate does that too.

/* Check for memory exhaustion and overflow. */
- if (toc_bytes + nbytes > total_bytes || toc_bytes + nbytes < toc_bytes)
+ if (toc_bytes + sizeof(shm_toc_entry) + nbytes > total_bytes)
{
  SpinLockRelease(&toc->toc_mutex);

shm_toc_freespace is introduced with shm_toc by original commit 6ddd5137b2, but is not used since then, so remove it.


Regards,
Zhang Mingli
Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: recovery modules
Next
From: Peter Eisentraut
Date:
Subject: Re: Common function for percent placeholder replacement