From f032b3acdf30e4632cb6d8e7e88f6dee9e0e0dc8 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Tue, 3 Feb 2026 10:32:30 +0000
Subject: [PATCH v1 1/3] Change StaticAssertStmt to StaticAssertDecl in
 basebackup.c

Changing the StaticAssertStmt to StaticAssertDecl results in having the same
StaticAssertDecl() in 2 functions. So, it makes more sense to move it to a
file scope instead.

Also as it depends on some computations based on 2 tar blocks, then define
TAR_TERMINATION_BLOCKS.
---
 src/backend/backup/basebackup.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
 100.0% src/backend/backup/

diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 463c0756b5e..6200777b032 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -78,6 +78,11 @@ typedef struct
 	pg_checksum_type manifest_checksum_type;
 } basebackup_options;
 
+#define TAR_TERMINATION_BLOCKS 2
+
+StaticAssertDecl(TAR_TERMINATION_BLOCKS * TAR_BLOCK_SIZE <= BLCKSZ,
+				 "BLCKSZ too small for " CppAsString2(TAR_TERMINATION_BLOCKS) " tar termination blocks");
+
 static int64 sendTablespace(bbsink *sink, char *path, Oid spcoid, bool sizeonly,
 							struct backup_manifest_info *manifest,
 							IncrementalBackupInfo *ib);
@@ -382,10 +387,8 @@ perform_base_backup(basebackup_options *opt, bbsink *sink,
 			else
 			{
 				/* Properly terminate the tarfile. */
-				StaticAssertDecl(2 * TAR_BLOCK_SIZE <= BLCKSZ,
-								 "BLCKSZ too small for 2 tar blocks");
-				memset(sink->bbs_buffer, 0, 2 * TAR_BLOCK_SIZE);
-				bbsink_archive_contents(sink, 2 * TAR_BLOCK_SIZE);
+				memset(sink->bbs_buffer, 0, TAR_TERMINATION_BLOCKS * TAR_BLOCK_SIZE);
+				bbsink_archive_contents(sink, TAR_TERMINATION_BLOCKS * TAR_BLOCK_SIZE);
 
 				/* OK, that's the end of the archive. */
 				bbsink_end_archive(sink);
@@ -635,10 +638,8 @@ perform_base_backup(basebackup_options *opt, bbsink *sink,
 		}
 
 		/* Properly terminate the tar file. */
-		StaticAssertStmt(2 * TAR_BLOCK_SIZE <= BLCKSZ,
-						 "BLCKSZ too small for 2 tar blocks");
-		memset(sink->bbs_buffer, 0, 2 * TAR_BLOCK_SIZE);
-		bbsink_archive_contents(sink, 2 * TAR_BLOCK_SIZE);
+		memset(sink->bbs_buffer, 0, TAR_TERMINATION_BLOCKS * TAR_BLOCK_SIZE);
+		bbsink_archive_contents(sink, TAR_TERMINATION_BLOCKS * TAR_BLOCK_SIZE);
 
 		/* OK, that's the end of the archive. */
 		bbsink_end_archive(sink);
-- 
2.34.1

