pgbackrest.git / summary / log / commit / refs
commit d32eb5bb542f80657cfcc86df7663339297bb431
Author: David Steele <david@pgmasters.net>
Date: Fri May 10 00:15:01 2024 +0000
Silence invalid Coverity complaint in jsonReadPush().
Coverity complains that the output from THROW_FMT will be unpredictable since the order of operations in the call is not deterministic, but it fails to understand that subsequent calls to jsonReadTypeNextIgnoreComma() are noops until the value has been processed.
Silence Coverity by assigning the actual type to a local variable so jsonReadTypeNextIgnoreComma() is only called once.
Also fix an adjacent comment typo.
src/common/type/json.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/common/type/json.c b/src/common/type/json.c
index 6cd3491a8..d3564f064 100644
--- a/src/common/type/json.c
+++ b/src/common/type/json.c
@@ -251,15 +251,19 @@ jsonReadPush(JsonRead *const this, const JsonType type, const bool key)
if (this->complete)
THROW(FormatError, "JSON read is complete");
- // Check that the requested type matches the actual type
- if (jsonReadTypeNextIgnoreComma(this) != type)
+ // Check that the requested type matches the actual type. The actual type needs to be assigned to a local variable or Coverity
+ // will complain about parameter order when jsonReadTypeNextIgnoreComma() is called again in THROW_FMT() even though it is a
+ // noop.
+ const JsonType typeActual = jsonReadTypeNextIgnoreComma(this);
+
+ if (typeActual != type)
{
THROW_FMT(
- JsonFormatError, "expected '%s' but found '%s' at: %s", strZ(strIdToStr(type)),
- strZ(strIdToStr(jsonReadTypeNextIgnoreComma(this))), this->json);
+ JsonFormatError, "expected '%s' but found '%s' at: %s", strZ(strIdToStr(type)), strZ(strIdToStr(typeActual)),
+ this->json);
}
- // If the container stack jas not been created yet
+ // If the container stack has not been created yet
if (this->stack == NULL)
{
ASSERT(!key);
[parent: bb8988b55175]