[SERVER-83541] Ensure StringData::compare uses handle return values outside {-1, 0, 1} Created: 22/Nov/23 Updated: 29/Nov/23 Resolved: 29/Nov/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 7.3.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Dan Larkin-York | Assignee: | Billy Donahue |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Backwards Compatibility: | Fully Compatible | ||||
| Operating System: | ALL | ||||
| Sprint: | Service Arch 2023-11-27, Service Arch 2023-12-11 | ||||
| Participants: | |||||
| Linked BF Score: | 153 | ||||
| Description |
|
Instead, we would like to audit the codebase for uses of StringData::compare to ensure that callers are not relying on -1/1 values specifically, but instead checking for negative/positive values. |
| Comments |
| Comment by Githook User [ 28/Nov/23 ] |
|
Author: {'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}Message: |
| Comment by Billy Donahue [ 22/Nov/23 ] |
|
Until |
| Comment by Dan Larkin-York [ 22/Nov/23 ] |
|
Updated the title and description to take the path Billy suggested instead. |
| Comment by Billy Donahue [ 22/Nov/23 ] |
|
We need to make callers tolerant of the range of StringData::compare. The exact values of -1,0,1 are never part of compare contracts. That's not what strcmp or char_traits::compare returns. They just do the "negative, zero, positive" bins for efficiency. They're usually returning the arithmetic difference between the first differing characters. The API of StringData has to match std::string_view exactly. |