Skip to content

Conversation

@richardleach
Copy link
Contributor

Coverity CID 316368 raises the concern that in the following comparison:
(OP(first) == OPEN && (sawopen = 1)
the intention might have been to compare sawopen, not assign to it.

The intention genuinely is to assign to sawopen, but since there are two
assignments in this fashion followed by two assignments in the subsequent
block, we can do a small refactor to consolidate the assignments in a way
that will hopefully keep Coverity happy.

@richardleach richardleach added Needs Triage defer-next-dev This PR should not be merged yet, but await the next development cycle labels Apr 27, 2022
@iabyn
Copy link
Contributor

iabyn commented Apr 28, 2022

Well this isn't just a refactor, it's a change in behaviour. Previously, sawlookahead was set if two conditions were true: OP(first) == IFMATCH && !first->flags; now it just needs the first condition. I have no idea whether it matters, but if it doesn't, I'd prefer this as two commits - a pure refactor, followed by removing of the extra test which (allegedly) isn't needed.

@richardleach
Copy link
Contributor Author

Previously, sawlookahead was set if two conditions were true: OP(first) == IFMATCH && !first->flags; now it just needs the first condition.

I was thinking that, w.r.t sawlookahead, the while block would only be entered if either:

  • (OP(first) == IFMATCH && !first->flags) is true
    or I suppose:
  • (PL_regkind[OP(first)] == CURLY && ARG1(first) > 0) is true and it happens to simultaneously be the case (I don't know if it's possible) that (OP(first) == IFMATCH && first->flags)

I could do something around that second case if so.

@richardleach
Copy link
Contributor Author

Alternatively, would structuring it like this be acceptable?

        while (1) {
            if (OP(first) == OPEN)
                sawopen = 1;
            /* for now we can't handle lookbehind IFMATCH*/
            else if (OP(first) == IFMATCH && !first->flags)
                sawlookahead = 1;
            else if (OP(first) == PLUS) {
                sawplus = 1;
                goto op_first_plus;
            } else if (OP(first) == MINMOD)
                sawminmod = 1;
            else if (
                   /* An OR of *one* alternative - should not happen now. */
                   (OP(first) == BRANCH && OP(first_next) != BRANCH)   ||
                   /* An {n,m} with n>0 */
                   (PL_regkind[OP(first)] == CURLY && ARG1(first) > 0) ||
                   (OP(first) == NOTHING && PL_regkind[OP(first_next)] != END )
            ) {
                /* Don't break */
            } else {
                break;
            }
                /*
                 * the only op that could be a regnode is PLUS, all the rest
                 * will be regnode_1 or regnode_2.
                 *
                 * (yves doesn't think this is true)
                 */
                first += regarglen[OP(first)];
              op_first_plus:
                first = NEXTOPER(first);
                first_next= regnext(first);            
        }

@iabyn
Copy link
Contributor

iabyn commented May 4, 2022 via email

@richardleach
Copy link
Contributor Author

Can Coverity be satisfied by using double parens

I'll set up a Coverity project and find out.

@richardleach
Copy link
Contributor Author

I haven't gotten around to setting up a Coverity project, nor am I likely to do so imminently. Almost identical other Coverity warnings have been marked as false positives in the project, so perhaps the most expedient thing to do here is do the same?

@demerphq
Copy link
Collaborator

demerphq commented Feb 12, 2023 via email

@demerphq
Copy link
Collaborator

Oh @iabyn already said that. My bad for replying before reading the full thread. Not enough coffee this morning. Sorry @richardleach .

@richardleach
Copy link
Contributor Author

I've updated the PR with just additional parens as recommended.

@richardleach richardleach merged commit 7ff8dd5 into Perl:blead Feb 13, 2023
@richardleach richardleach deleted the hydahy/regcomp_PWASSIGN branch February 14, 2023 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting response defer-next-dev This PR should not be merged yet, but await the next development cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants