[SERVER-37161] Coverity analysis defect 105024: Macro compares unsigned to 0 Created: 17/Sep/18  Updated: 29/Oct/23  Resolved: 27/Sep/18

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.1.4

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Jonathan Reams
Resolution: Fixed Votes: 0
Labels: coverity
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Security 2018-10-08
Participants:

 Description   

An unsigned value can never be less than 0

Defect 105024 (STATIC_C)
Checker NO_EFFECT (subcategory unsigned_compare_macros)
File: /src/mongo/transport/service_executor_reserved.cpp
Function mongo::transport::ServiceExecutorReserved::_startWorker()::[lambda() (instance 1)]::operator ()() const::[lambda() (instance 1)]::operator ()() const
/src/mongo/transport/service_executor_reserved.cpp, line: 90
This greater-than-or-equal-to-zero comparison of an unsigned value is always true. "this->__coverity_captured_this->_numRunningWorkerThreads.subtractAndFetch(1U) >= 0U".

                invariant(_numRunningWorkerThreads.subtractAndFetch(1) >= 0);



 Comments   
Comment by Jonathan Reams [ 27/Sep/18 ]

This was fixed by reverting https://github.com/mongodb/mongo/commit/4fe0de9a46492e9fa747e88234e483d172d9c410.

Comment by Eric Milkie [ 17/Sep/18 ]

I mistakenly assumed _numRunningWorkerThreads was signed when I reviewed the change that added this invariant. I suppose we should just remove the invariant now, as there isn't an easy way to detect underflow here.

Generated at Thu Feb 08 04:45:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.