Skip to content

Commit 3dbc4fa

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 | ^~~~~ In C a pointer to the first field of a structure and a pointer to the structure itself are always equal. Add a compile-time assertion check in case the field magic is not the first field in the structure PtrackMapHdr in the future. Thanks to Maksim Orlov for the review.
1 parent 3d6ccc6 commit 3dbc4fa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

engine.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,17 @@ ptrackCheckpoint(void)
394394
*
395395
* Write both magic and varsion_num at once.
396396
*/
397-
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) &ptrack_map->magic,
397+
398+
/*
399+
* Previously we read from the field magic, now we read from the beginning
400+
* of the structure PtrackMapHdr. Make sure nothing has changed since then.
401+
*/
402+
StaticAssertStmt(
403+
offsetof(PtrackMapHdr, magic) == 0,
404+
"old write format for PtrackMapHdr.magic and PtrackMapHdr.version_num "
405+
"is not upward-compatible");
406+
407+
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) ptrack_map,
398408
offsetof(PtrackMapHdr, init_lsn));
399409

400410
init_lsn = pg_atomic_read_u64(&ptrack_map->init_lsn);

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