Skip to content

Conversation

@NWilson
Copy link
Member

@NWilson NWilson commented Dec 3, 2024

One of these appears in Coverity's dashboard; the rest are from clang-scan.

See #576

single-char opcodes. */

reqvary = (repeat_min == repeat_max)? 0 : REQ_VARY;
op_type = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang is correct here. The assignment to op_type is provably a dead assignment. What's more... I reckon it hurts rather than helps, because if there's a branch in the code that should be assigning to op_type but forgets, this would suppress warnings about use-of-uninitialised!

buffer[0] = new_start;
buffer[1] = new_end;
buffer += 2;
(void)buffer;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some clearly useless assignments here, but they're OK to keep, because they ensure the buffer is correctly tracked if someone extends the function later. Easy suppression.

{
allow_zero = TRUE;
codevalue = *(++code); /* Codevalue will be one of above BRAs */
++code; /* The following opcode will be one of the above BRAs */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang is correct. We are writing a value to codevalue which is provably never used.

src/pcre2grep.c Outdated
}

while ((patlen = sizeof(buffer)) && read_pattern(buffer, &patlen, f))
while ((patlen = sizeof(buffer), read_pattern(buffer, &patlen, f)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid coverity. It seems unable to reason about the (patlen = sizeof(buffer)) && expression, which assigns to patlen, and then unconditionally continues (because sizeof(buffer) is always > 0).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ikely going to add a -Wcomma warning though and the original code was clearer about intention.

isn't there a pragma or other way to suppress this from coverity without affecting code quality?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Wcomma allows assignments on the LHS of a comma operator, so this should be accepted.

I'm not sure the original code was clearer anyway. We're not logically doing an &&: we want to do something with side-effects on the left, ignore whatever it evaluates to, and then execute the right.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite it to while (TRUE), set variable, break if read_pattern fails. This is not a nice code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; I've done Zoltan's improvement.

ret = (int)len;
}

PCRE2_ASSERT(len > 0 || preg != NULL);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an assertion here lets Clang reason about when preg is NULL. There was no bug, but static analysis wasn't able to work out that checking len was equivalent to checking preg != NULL.

src/pcre2grep.c Outdated
}

while ((patlen = sizeof(buffer)) && read_pattern(buffer, &patlen, f))
while ((patlen = sizeof(buffer), read_pattern(buffer, &patlen, f)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ikely going to add a -Wcomma warning though and the original code was clearer about intention.

isn't there a pragma or other way to suppress this from coverity without affecting code quality?

@NWilson NWilson force-pushed the user/niwilson/minor-warnings branch from f7f8679 to 6d300e4 Compare December 4, 2024 15:22
@NWilson NWilson force-pushed the user/niwilson/minor-warnings branch from 6d300e4 to b879592 Compare December 6, 2024 11:37
@zherczeg
Copy link
Collaborator

zherczeg commented Dec 6, 2024

@carenas are the changes ok?

@NWilson
Copy link
Member Author

NWilson commented Dec 7, 2024

I think it's OK to merge. Carlo's only request was that there (might be, unconfirmed) a -Wcomma warning, but I've removed the comma.

@NWilson NWilson merged commit c03e7b0 into PCRE2Project:master Dec 7, 2024
21 checks passed
@NWilson NWilson deleted the user/niwilson/minor-warnings branch December 7, 2024 19:32
@carenas
Copy link
Contributor

carenas commented Dec 8, 2024

Apologies for the delay, validating the changes was indeed made more difficult by the rebasing of these changes, but it seems that another concern I had might had also sneaked in.

It was previously a regression that broke building in AIX with xlc, because it will falsely recognize the compiler as supporting a builtin that it doesn't have because the detection code was optimized out because it was deemed uneeded and without side effects.

@carenas
Copy link
Contributor

carenas commented Dec 8, 2024

got an AIX 7.1 system to validate, and seems my concerns were unfunded, eventhough there might be still problems with make dist as a snapshot from HEAD failed with:

carenasgm@gcc111:[/home/carenasgm/pcre2-10.45-DEV]cat RunGrepTest.log
Testing pcre2grep version 10.45-DEV 2024-06-09
Testing pcre2grep main features
--- ./testdata/grepoutput       2024-12-08 04:13:29.000000000 -0800
+++ testtrygrep 2024-12-08 04:22:23.000000000 -0800
@@ -496,10 +496,7 @@
  ./testdata/grepinput:456
  ./testdata/grepinput3:0
  ./testdata/grepinput8:0
- ./testdata/grepinputBad8:0
- ./testdata/grepinputBad8_Trail:0
  ./testdata/grepinputM:0
- ./testdata/grepinputUN:0
  ./testdata/grepinputv:1
  ./testdata/grepinputx:0
  RC=0
@@ -728,8 +725,6 @@
  ---------------------------- Test 96 -----------------------------
  ./testdata/grepinput3
  ./testdata/grepinput8
- ./testdata/grepinputBad8
- ./testdata/grepinputBad8_Trail
  ./testdata/grepinputx
  RC=0
  ---------------------------- Test 97 -----------------------------
@@ -841,10 +836,7 @@
  testdata/grepinput:469
  testdata/grepinput3:0
  testdata/grepinput8:0
- testdata/grepinputBad8:0
- testdata/grepinputBad8_Trail:0
  testdata/grepinputM:2
- testdata/grepinputUN:0
  testdata/grepinputv:3
  testdata/grepinputx:6
  TOTAL:480
@@ -863,10 +855,7 @@
  469
  0
  0
- 0
- 0
  2
- 0
  3
  6
  480
@@ -874,9 +863,6 @@
  ---------------------------- Test 118 -----------------------------
  testdata/grepinput3
  testdata/grepinput8
- testdata/grepinputBad8
- testdata/grepinputBad8_Trail
- testdata/grepinputUN
  RC=0
  ---------------------------- Test 119 -----------------------------
  123
FAIL RunGrepTest (exit status: 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants