Skip to content

Commit 033471d

Browse files
author
Marina Polyakova
committed
PGPRO-5646: remove compiler warning (gcc 11.2.0)
In function ‘ptrack_write_chunk’, inlined from ‘ptrackCheckpoint’ at engine.c:397:2: engine.c:78:13: warning: ‘write’ reading 8 bytes from a region of size 4 [-Wstringop-overread] 78 | if (write(fd, chunk, size) != size) | ^~~~~~~~~~~~~~~~~~~~~~ In file included from engine.c:47: engine.c: In function ‘ptrackCheckpoint’: engine.h:55:25: note: source object ‘magic’ of size 4 55 | char magic[PTRACK_MAGIC_SIZE]; | ^~~~~ In file included from engine.c:22: /usr/include/unistd.h:378:16: note: in a call to function ‘write’ declared with attribute ‘access (read_only, 2, 3)’ 378 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur | ^~~~~ To avoid changing other code for the fields magic and version_num in the structure PtrackMapHdr, use two calls to ptrack_write_chunk to write them to the file. (This function is called a few times later, so why not add another call?) Add a compile-time assertion check that nothing has actually changed (e.g. alignment is fine).
1 parent 3d6ccc6 commit 033471d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

engine.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,22 @@ ptrackCheckpoint(void)
391391
* We are writing ptrack map values to file, but we want to simply map it
392392
* into the memory with mmap after a crash/restart. That way, we have to
393393
* write values taking into account all paddings/alignments.
394-
*
395-
* Write both magic and varsion_num at once.
396394
*/
395+
396+
/*
397+
* Earlier we wrote both magic and varsion_num at once. Make sure nothing
398+
* has changed since then (e.g. alignment is fine).
399+
*/
400+
StaticAssertStmt(
401+
sizeof(ptrack_map->magic) + sizeof(ptrack_map->version_num) ==
402+
offsetof(PtrackMapHdr, init_lsn),
403+
"old write format for PtrackMapHdr.magic and PtrackMapHdr.version_num "
404+
"is not upward-compatible");
405+
397406
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) &ptrack_map->magic,
398-
offsetof(PtrackMapHdr, init_lsn));
407+
sizeof(ptrack_map->magic));
408+
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) &ptrack_map->version_num,
409+
sizeof(ptrack_map->version_num));
399410

400411
init_lsn = pg_atomic_read_u64(&ptrack_map->init_lsn);
401412

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy