Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ucCrJ-00AEJl-TI for pgsql-committers@arkaria.postgresql.org; Thu, 17 Jul 2025 00:52:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ucCrH-00FQAY-W9 for pgsql-committers@arkaria.postgresql.org; Thu, 17 Jul 2025 00:52:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ucCrH-00FQAQ-Ox for pgsql-committers@lists.postgresql.org; Thu, 17 Jul 2025 00:52:24 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ucCrF-008AGi-3C for pgsql-committers@lists.postgresql.org; Thu, 17 Jul 2025 00:52:24 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-32f1df5703aso3093431fa.3 for ; Wed, 16 Jul 2025 17:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752713540; x=1753318340; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=uMEKem1TpbjTnbetzNpmpkpJorSBqaMHozhgUdriM6Y=; b=Iuyixk7c3JJZhxo+z/nwDf6nstwG/rpdjlzhxZm+c82HkQahBiCHQH59bJeRVA2hw/ vOU8J0sf4MsTNWibkH8xWYQlsFt3Davz0MAWZtLC4oN2rFN4ujBJs7srZTT/s42ZHE/A 23mxa9aIdaJQTT6RrZT4fbICVvHBVTDrBoZCIleI869+Y78fwn/PpfRrEAcuZ/Yl7e9u SSCeLIMq03MOz3Obuy/FimBAb8t3aaM7uxUb4fhxYF6RLt+0O8SUoQstc8J+6+TNSzOg uFw85d7FdTIOraypVBDbvQbguKsxh2VxFBrkU3E9osXGRR5SIA9cZqWuVgNfbuDrGtvw EISg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752713540; x=1753318340; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uMEKem1TpbjTnbetzNpmpkpJorSBqaMHozhgUdriM6Y=; b=sC+C/gBeqS2DhL+M5k3mVw4hb5O/T+GM5pcVdJaKRYTltKnBUVwv8CztnIfzvtVuVa ydvcgzTwqCqRTILsOWb4E6eRPxJKA3opNel/XT+jLRabc3KZiVN+UkQDN6SdVXwiiAAd a50wKpZeTSK+uEyC24yE0TMGccgcQDy60pGtwnP8FozUPosodIFVR/o0u+newPHO6OIN NjGtsczD2pt7g02Air19NGUegFjlBN9jpqVFm2gmio/TZdhxf910InUxJkEg1kck38lO j8Fuw6+99vFq0EgS7Fs3/bjhBQSJK6TRdCLrJEncpnVp/WPE1SmBADgpQEshOJKeekea o1zA== X-Forwarded-Encrypted: i=1; AJvYcCVLux0b79rUGROwwdiBzFrewh8+I1CP34bMUP4avxf+Y4bgmtJ2HpGK5No6xCgS1vo0xIbwF6I8pGuNOuYgXKs/@lists.postgresql.org X-Gm-Message-State: AOJu0YyPdlsskr83p6Zs/R4rnJhyUBxyb34Mv4Sn6BFqjcV+7aSL2w4A paHwcfIs0OgZKYIhgjUSB9l/wvSCwXDctBSce8HbfuYsh9pDe+CQHQ0aTuF9yGB3HsZaxQ4AYkJ osPkrYWyev191OZEn0fbNG2+CYBSlgUMgmLiE X-Gm-Gg: ASbGnct7MuSi2kCKPd6yjItHd09igrzhLXsnK8SGykUoqunFFqXThq1CmJxiQkroD6/ fnf+YcPSpWc9AYTsUvZ4b2tN+7wRJfErCrKXEJromwmWxo2aNF0f+KQk+crIY2wsvxos7A0ZmF2 /EaxQ1cRt+7ZsCWSF46ZoRw9MG+qTDTES/Cj9AstyVAaEO1Co9G2ICEoC2GqFQZSnyPsm5QUdgs B2OFbmMQJZw0SQZiqr/NvDvaUUdNFMDF084tZXM X-Google-Smtp-Source: AGHT+IFuOz34sh/vqH/kdldkxH/bICEmn70XvzZmH0s2Cpadbg8qJViq2jxCGHS5TP3z/nB/tGmCZpYLKqrZIykElwU= X-Received: by 2002:a2e:a494:0:b0:32b:82bf:cc53 with SMTP id 38308e7fff4ca-3308e56d7acmr9919121fa.31.1752713540001; Wed, 16 Jul 2025 17:52:20 -0700 (PDT) MIME-Version: 1.0 References: <6c00a8b2-0c40-44f0-b603-f6ae28b7694a@eisentraut.org> <1244428.1752677780@sss.pgh.pa.us> In-Reply-To: <1244428.1752677780@sss.pgh.pa.us> From: David Rowley Date: Thu, 17 Jul 2025 12:52:07 +1200 X-Gm-Features: Ac12FXyPaIrYWCDNp42rHN5u39EgTRSg5V8x31norsABLr-OFyC4J4duaEgOWhQ Message-ID: Subject: Re: pgsql: pg_logicalinspect: Fix possible crash when passing a directory p To: Tom Lane Cc: Peter Eisentraut , Masahiko Sawada , pgsql-committers@lists.postgresql.org Content-Type: multipart/mixed; boundary="000000000000f20257063a156bd4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f20257063a156bd4 Content-Type: text/plain; charset="UTF-8" On Thu, 17 Jul 2025 at 02:56, Tom Lane wrote: > Looking again at the code for ereport_domain(), I wondered if > something like this would help MSVC see through it: > > #define ereport_domain(elevel, domain, ...) \ > do { \ > const int elevel_ = (elevel); \ > + const bool is_error_ = (elevel_ >= ERROR); \ > pg_prevent_errno_in_scope(); \ > if (errstart(elevel_, domain)) \ > __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \ > - if (elevel_ >= ERROR) \ > + if (is_error_) \ > pg_unreachable(); \ > } while(0) > > This preserves single evaluation of the elevel parameter, and > perhaps it'd move the needle on whether the compiler thinks > is_error_ is a compile-time constant. I'm just guessing > though, don't have this compiler to test with. I tried this and it unfortunately doesn't fix the issue. I expect that the compiler is losing the ability to detect const-ness through the "const" variables, and since is_error_ is being set from elevel_ it's not seen as compile-time detectability constant either. I spent a bit more time searching for a solution and did find something that works well enough for this case in [1]. Unfortunately, it only works with C11. See attached .c file and output below. C11 test: > cl /std:c11 isconst.c && isconst.exe Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35211 for x64 Copyright (C) Microsoft Corporation. All rights reserved. isconst.c Microsoft (R) Incremental Linker Version 14.44.35211.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:isconst.exe isconst.obj 0 1 1 C99 test: > cl isconst.c && isconst.exe Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35211 for x64 Copyright (C) Microsoft Corporation. All rights reserved. isconst.c isconst.c(12): error C2059: syntax error: 'type' isconst.c(13): error C2059: syntax error: 'type' isconst.c(14): error C2059: syntax error: 'type' I didn't manage to find anything that works in C99. David [1] https://www.reddit.com/r/C_Programming/comments/o3ekqe/i_think_i_found_a_c11_compliant_way_to_detect/ --000000000000f20257063a156bd4 Content-Type: text/plain; charset="US-ASCII"; name="isconst.c" Content-Disposition: attachment; filename="isconst.c" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_md6o9zb40 I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIF9fYnVpbHRpbl9jb25zdGFudF9wKHgpIF9HZW5l cmljKCgxID8gKCh2b2lkKikoKHgpKih1aW50cHRyX3QpMCkpIDogJihpbnQpezF9KSwgaW50Kjog MSwgdm9pZCo6IDApCgojZGVmaW5lIHRlc3QoZSkgcHJpbnRmKCIlZFxuIiwgX19idWlsdGluX2Nv bnN0YW50X3AoZSkpOwoKI2RlZmluZSBFUlJPUiAxCgppbnQgbWFpbih2b2lkKQp7CglpbnQgdiA9 IDE7Cgl0ZXN0KHYpOwoJdGVzdChFUlJPUik7Cgl0ZXN0KDEpOwoJcmV0dXJuIDA7Cn0K --000000000000f20257063a156bd4--