]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Reduce the scope of volatile qualifiers
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Mar 2026 09:01:44 +0000 (10:01 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Mar 2026 09:02:28 +0000 (10:02 +0100)
Commit c66a7d75e652 introduced a new "cast discards ‘volatile’"
warning (-Wcast-qual) in vac_truncate_clog().

Instead of making use of unvolatize(), remove the warning by reducing the
scope of the volatile qualifier (added in commit 2d2e40e3bef) to only
2 fields.

Also do the same for vac_update_datfrozenxid(), since the intent of
commit f65ab862e3b was to prevent the same kind of race condition that
commit 2d2e40e3bef was fixing.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Suggested-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/aZ3a%2BV82uSfEjDmD%40ip-10-97-1-34.eu-west-3.compute.internal

src/backend/commands/vacuum.c

index 03932f45c8ade610c44cd565d7b304e820490995..b9840637783cfa769097e968acef97debd645fa6 100644 (file)
@@ -1665,9 +1665,11 @@ vac_update_datfrozenxid(void)
 
        while ((classTup = systable_getnext(scan)) != NULL)
        {
-               volatile FormData_pg_class *classForm = (Form_pg_class) GETSTRUCT(classTup);
-               TransactionId relfrozenxid = classForm->relfrozenxid;
-               TransactionId relminmxid = classForm->relminmxid;
+               Form_pg_class classForm = (Form_pg_class) GETSTRUCT(classTup);
+               volatile TransactionId *relfrozenxid_p = &classForm->relfrozenxid;
+               volatile TransactionId *relminmxid_p = &classForm->relminmxid;
+               TransactionId relfrozenxid = *relfrozenxid_p;
+               TransactionId relminmxid = *relminmxid_p;
 
                /*
                 * Only consider relations able to hold unfrozen XIDs (anything else
@@ -1869,9 +1871,11 @@ vac_truncate_clog(TransactionId frozenXID,
 
        while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
        {
-               volatile FormData_pg_database *dbform = (Form_pg_database) GETSTRUCT(tuple);
-               TransactionId datfrozenxid = dbform->datfrozenxid;
-               TransactionId datminmxid = dbform->datminmxid;
+               Form_pg_database dbform = (Form_pg_database) GETSTRUCT(tuple);
+               volatile TransactionId *datfrozenxid_p = &dbform->datfrozenxid;
+               volatile TransactionId *datminmxid_p = &dbform->datminmxid;
+               TransactionId datfrozenxid = *datfrozenxid_p;
+               TransactionId datminmxid = *datminmxid_p;
 
                Assert(TransactionIdIsNormal(datfrozenxid));
                Assert(MultiXactIdIsValid(datminmxid));