-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Mishandling Japanese Era and Leap Year in calculations #1354
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
C++: Mishandling Japanese Era and Leap Year in calculations #1354
Conversation
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.
Hi, this PR looks really valuable. I've suggested quite a few minor changes, let me know if you'd prefer us to make them instead of you.
I've still to look at the tests and try these queries out a bit.
cpp/ql/src/Likely Bugs/JapaneseEra/ConstructorOrMethodWithExactEraDate.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/JapaneseEra/ConstructorOrMethodWithExactEraDate.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UnsafeArrayForDaysOfYear.qhelp
Outdated
Show resolved
Hide resolved
bool isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); | ||
int *items = new int[isLeapYear ? 366 : 365]; | ||
// ... | ||
delete[] items; |
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.
Is this the best solution to recommend, or should we suggest simply increasing the array size to 366
all the time?
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.
There is no silver bullet for this pattern. I am afraid that recommending to always use 366-item arrays may hide the fact that the index offset may still be incorrect. The index offset value must also be set properly for leap years, so devs using this pattern should always be aware of leap years to calculate the offset value correctly. We could add a comment to make this clear.
<li>U.S. Naval Observatory Website - <a href="https://aa.usno.navy.mil/faq/docs/calendars.php"> Introduction to Calendars</a></li> | ||
<li>Wikipedia - <a href="https://en.wikipedia.org/wiki/Leap_year_bug"> Leap year bug</a> </li> | ||
<li>Microsoft Azure blog - <a href="https://azure.microsoft.com/en-us/blog/is-your-code-ready-for-the-leap-year/"> Is your code ready for the leap year?</a> </li> | ||
</references> |
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.
The qhelp-preview
job failed with [ERROR] ql/cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qhelp:16:1: XML document structures must start and end within the same entity.
. I believe it wants you to add a </qhelp>
tag here.
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.
How can we test the qhelp files to avoid these errors in the future?
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.
I personally tend to just rely on the qhelp-preview
job on the pull request, but I can see that an offline tool might be helpful if you're writing a lot of help.
@semmledocs-ac what do you recommend?
Can you run the autoformatter on the QL files? |
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.
Thanks for submitting these. Very nice accompanying QHelp. I've done an editorial check of the documentation and raised some comments - all small stuff. As per Geoffrey's comment, let us know if you'd prefer us to make these changes instead of you.
cpp/ql/src/Likely Bugs/JapaneseEra/ConstructorOrMethodWithExactEraDate.qhelp
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/JapaneseEra/ConstructorOrMethodWithExactEraDate.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/JapaneseEra/StructWithExactEraDate.qhelp
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UnsafeArrayForDaysOfYear.qhelp
Outdated
Show resolved
Hide resolved
cpp/ql/src/Likely Bugs/Leap Year/UnsafeArrayForDaysOfYear.qhelp
Outdated
Show resolved
Hide resolved
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.
Denis, thanks for making those changes.
This all LGTM now from my point of view.
Changes LGTM as well. All of the changes I asked for have been made as well. I do have an unanswered question above. |
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.
I think this is about ready to merge and we're keen to do so. We'll probably make a few more refinements to it in the coming days.
Thank you for your contribution!
There were a couple of pull request check failures due to issues in the |
CPP: Fixes for C++: Mishandling Japanese Era and Leap Year in calculations github#1354
Please feel free to merge once it's ready! Thank you! |
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.
Let's not delay any further and merge this. There are still a couple of qhelp errors (my fault I think), which I will fix in a follow-up PR.
These queries check for various scenarios where the dates may be mishandled.