[SERVER-5684] Possible number truncation in query.cpp? Created: 23/Apr/12  Updated: 11/Jul/16  Resolved: 30/Apr/12

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

Type: Question Priority: Major - P3
Reporter: Randolph Tan Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Code snippet below is from queryWithQueryOptimizer @ ops/query.cpp and it tries to cast long long to int and assign it to a long long:

if ( dbprofile || duration >= cmdLine.slowMS ) {
  curop.debug().nscanned = (int)( cursor ? cursor->nscanned() : 0 );  // <-- why is there a cast?
  curop.debug().ntoskip = pq.getSkip();
}



 Comments   
Comment by auto [ 30/Apr/12 ]

Author:

{u'login': u'amcfague', u'name': u'Andrew McFague', u'email': u'redmumba@gmail.com'}

Message: SERVER-5684: Removing unnecessary cast from profiling code.

Since curop.debug().nscanned is a `long long`, and the return of the
`nscanned()` function is also a `long long`, casting is unnecessary here
as the false value `0` will correctly be coerced to a `long long`.
However, to improve readability, I have specifically marked the 0
constant as `0LL`.

Signed-off-by: Randolph Tan <randolph@10gen.com>
Branch: master
https://github.com/mongodb/mongo/commit/100b489788f4c335e6df88606804c589f7cd6a5b

Comment by Andrew McFague [ 30/Apr/12 ]

Sounds like something left from when it was actually an integer; that's the only logic I can see. I have updated to (a) remove the cast, and (b) correctly identify the constant `0` as a `long long` (even though this will be correct cast normally).

Submitted a pull request here: https://github.com/mongodb/mongo/pull/218

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