Skip to content

Conversation

@mhdawson
Copy link
Member

Coverity reported some calls that had no effect,
remove them

Signed-off-by: Michael Dawson [email protected]

Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]>
@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jan 18, 2022
@mhdawson
Copy link
MemberAuthor

I guess this might explain why the call was made ? On OSX:

../src/histogram.cc:162:5: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
map->Set(
^~~~~~~~

@mhdawson
Copy link
MemberAuthor

Not sure why it did not fail locally, as seems to be reported for linux as well. Maybe my local compiler version?

@mhdawson
Copy link
MemberAuthor

I think I understand what is going on here:

  • Set returns MaybeLocal and has V8_WARN_UNUSED_RESULT -> which results in a warning if the return value from Set is not used.
  • IsEmpty() is one of the few methods on MaybeLocal that does not also have a V8_WARN_UNUSED_RESULT. Since it is marked const however, coverity knows that it does do anything other than satisfying the compiler.

Our options would seem to be:

  • use ToLocalChecked instead of IsEmpty as it is not const and does not have V8_WARN_UNUSED_RESULT
  • add a co-verity comment telling it to ignore the line.

@mhdawson
Copy link
MemberAuthor

ToLocalChecked will crash if the result is empty so we'd only use that if we want to know that the Set failed versus just ignoring and continuing.

@mhdawson
Copy link
MemberAuthor

No local test failures with ToLocalChecked so I think that means it's not expected that the Set can fail.

@mhdawson
Copy link
MemberAuthor

@jasnell since I think you are the main contributor to this part of the code do you think I should:

  • use ToLocalChecked instead of IsEmpty as it is not const and does not have V8_WARN_UNUSED_RESULT
  • add a co-verity comment telling it to ignore the line.

Some additional explanation/discussion above.

Copy link
Member

@RaisinTenRaisinTen left a comment

Choose a reason for hiding this comment

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

This would crash if an exception is thrown between subsequent V8 calls in any of these binding functions. As a solution, instead of removing the IsEmpty() checks, we should pass on the return value of the Set() call from the lambdas and in

template <typename Iterator>
voidHistogram::Percentiles(Iterator&& fn){
Mutex::ScopedLock lock(mutex_);
hdr_iter iter;
hdr_iter_percentile_init(&iter, histogram_.get(), 1);
while (hdr_iter_next(&iter)){
double key = iter.specifics.percentiles.percentile;
fn(key, iter.value);
}
}

while calling fn(), we should check if the returned value is an empty maybe and return early if that's the case.

@addaleax
Copy link
Member

+1 to what @RaisinTen said.

If that's not an option, we should use USE(x) instead of x.IsEmpty(), which is literally there for the very purpose of avoiding "unused value" warnings.

@jasnell
Copy link
Member

I suggest just using USE(...) here as Anna mentioned.

@mhdawson
Copy link
MemberAuthor

Thanks, I'll look at @RaisinTen's suggestion and if that does not seem practical add the USE()

@mhdawson
Copy link
MemberAuthor

Code higher up looks like

getpercentilesBigInt(){if(!isHistogram(this))thrownewERR_INVALID_THIS('Histogram');this[kMap].clear();this[kHandle]?.percentilesBigInt(this[kMap]);returnthis[kMap];}

@mhdawson
Copy link
MemberAuthor

Returning the result of map-Set up to the JavaScript would only let us return undefined/null instead of an empty map, but I think this[kHandle]?.percentilesBigInt(this[kMap]); may already lead to the possibility of an empty map in case of an error/invalid state.

For that reason I think just using USE makes sense, will update with that.

Signed-off-by: Michael Dawson <[email protected]>
@richardlau
Copy link
Member

Commit message will need updating to reflect the new approach.

@mhdawson
Copy link
MemberAuthor

@RaisinTen pushed update to change to add USE()

Copy link
Member

@RaisinTenRaisinTen left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot
Copy link
Collaborator

mhdawson added a commit that referenced this pull request Jan 28, 2022
Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]> PR-URL: #41579 Reviewed-By: Yash Ladha <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
@mhdawson
Copy link
MemberAuthor

Landed in d86dcaa

Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]> PR-URL: nodejs#41579 Reviewed-By: Yash Ladha <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
ruyadorno pushed a commit that referenced this pull request Feb 8, 2022
Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]> PR-URL: #41579 Reviewed-By: Yash Ladha <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
@ruyadornoruyadorno mentioned this pull request Feb 8, 2022
danielleadams pushed a commit that referenced this pull request Mar 2, 2022
Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]> PR-URL: #41579 Reviewed-By: Yash Ladha <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
danielleadams pushed a commit that referenced this pull request Mar 3, 2022
Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]> PR-URL: #41579 Reviewed-By: Yash Ladha <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
danielleadams pushed a commit that referenced this pull request Mar 14, 2022
Coverity reported some calls that had no effect, remove them Signed-off-by: Michael Dawson <[email protected]> PR-URL: #41579 Reviewed-By: Yash Ladha <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Richard Lau <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@mhdawson@addaleax@jasnell@richardlau@nodejs-github-bot@yashLadha@RaisinTen