-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix CodeQL warnings, part 2 #3585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Bugs: VSO-1773907, VSO-1773908, VSO-1773909, VSO-1773910 This is the `[cpp/conditionallyuninitializedvariable]` warning: "The status of this call to `xtime_get` is not checked, potentially leaving `now` uninitialized."
Bug: VSO-1772889
This is the `[cpp/conditionallyuninitializedvariable]` warning:
"The status of this call to externally defined (SAL) `_BitScanReverse`
is not checked, potentially leaving `_Result` uninitialized."
This code is safe because `_Floor_of_log_2()` begins with:
```cpp
_Value |= size_t{1}; // avoid undefined answer from _BitScanReverse for 0
```
Bugs: VSO-1772915, VSO-1772918, VSO-1772919 This is the `[cpp/conditionallyuninitializedvariable]` warning: "The status of this call to externally defined (SAL) `_BitScanForward` is not checked, potentially leaving `_Offset` uninitialized." This code is safe because each callsite has tested `if (_Bingo != 0)`.
Bugs: VSO-1772995, VSO-1772900, VSO-1772896 These `[cpp/conditionallyuninitializedvariable]` warnings are of the form: "The status of this call to externally defined (SAL) `_BitScanReverse` is not checked, potentially leaving `_H_pos` uninitialized." We're looking for a known element in these vector registers, so we have a guarantee that `_Mask` is non-zero and therefore `_H_pos` is always initialized.
frederick-vs-ja
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
It seems we can kill the name xtime without breaking ABI, since all non-inline functions involving xtime in STL are extern "C", which means that changing the name of a parameter type doesn't affect the mangled name. I'll try this in a later PR.
|
Have you filled a bug against CodeQL about incorrect handling of |
|
We've looked into reporting bugs to CodeQL but AFAIK we don't know how yet 😿 |
|
|
||
| // Find the smallest horizontal index | ||
| _BitScanForward(&_H_pos, _Mask); // lgtm [cpp/conditionallyuninitializedvariable] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray newline (possibly above as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These newlines were intentional. Because the LGTM comment (apparently) has to appear on the same line, I had to move the existing comment above. Then I introduced newlines above and below, to make it clear that the above comment applies only to the bitscan intrinsic, and not to following code.
|
|
||
| // Find the largest horizontal index | ||
| _BitScanReverse(&_H_pos, _Mask); // lgtm [cpp/conditionallyuninitializedvariable] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto stray newline
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Part 1: #3489
CodeQL is emitting more warnings in the STL's separately compiled sources, resulting in the automatic creation of high-priority bugs in the internal database.
This PR introduces no behavioral changes, nor does it affect the STL's dllexports.
xtime_getxtime_getCodeQL warnings.[cpp/conditionallyuninitializedvariable]warning:This is the most interesting one. We never documented or supported the non-Standard
xtimeAPI (and we really should get rid of these non-Standard identifiers someday). All of our calls toxtime_getare insrc, and all of them are exactlyxtime_get(&now, TIME_UTC). In this case, it always succeeds and calls thestatichelpersys_get_time. So, we can clean up this code and eradicate all occurrences of this warning.inc/xtimec.h, we're going to drop the declaration ofxtime_get. This is paired with marking the definition insrc/xtime.cppas preserved for bincompat.threadandcondition_variable, identify unused dllexports #3532, this does not affect the dllexport surface, because the declaration and the definition match (specifically_CRTIMP2_PUREand__cdecl).inc/xtimec.hdeclares_Xtime_get2, but only when building the STL. (This is because we don't have any convenient header insrcthat's dragged in by the relevant TUs.)_CRTIMP2_PUREand__cdeclbecause it is not dllexported - it allows STL TUs to call a function defined in another STL TU, but it isn't for users to interact with. (The_Uglyname will have external linkage when static linking, but is unobservable to users.)src/xtime.cppchanges thestatichelpersys_get_time(unobservable by all other TUs) into the_Xtime_get2helper (for STL TUs), with the same comment.<xbit_ops.h><xbit_ops.h>CodeQL warnings.[cpp/conditionallyuninitializedvariable]warning:_Floor_of_log_2()begins with:vector_algorithms.cppif-statements.if (_Bingo != 0)easier to see in the following change:vector_algorithms.cppCodeQL warnings.[cpp/conditionallyuninitializedvariable]warning:if (_Bingo != 0).vector_algorithms.cppCodeQL warnings.[cpp/conditionallyuninitializedvariable]warnings are of the form:_Maskis non-zero and therefore_H_posis always initialized.