Skip to content
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

Fix an issue in TimeSeriesProperty #18952

Merged
merged 5 commits into from
Feb 27, 2017

Conversation

raquelalvarezbanos
Copy link
Contributor

@raquelalvarezbanos raquelalvarezbanos commented Feb 21, 2017

Description of work.

To test:

  • This has to be tested on Windows, debug mode.
  • Run the script in the issue description, Mantid shouldn't crash.
  • Make sure that the new unit test fails without this fix.
  • I could have added a similar check for the property values before this line, but I think it is unnecessary. Make sure you agree with me.

Fixes #18944.

No need to mention this in the release notes, as the bug only happens on Windows in debug mode.


Reviewer

Please comment on the following (full description):

Code Review
  • Is the code of an acceptable quality?
  • Does the code conform to the coding standards? Is it well structured with small focussed classes/methods/functions?
  • Are there unit/system tests in place? Are the unit tests small and test the a class in isolation?
  • If there are changes in the release notes then do they describe the changes appropriately?
Functional Tests
  • Do changes function as described? Add comments below that describe the tests performed?

  • How do the changes handle unexpected situations, e.g. bad input?

  • Has the relevant documentation been added/updated?

  • Is user-facing documentation written in a user-friendly manner?

  • Has developer documentation been updated if required?

  • Does everything look good? Comment with the ship it emoji but don't merge. A member of @mantidproject/gatekeepers will take care of it.

@raquelalvarezbanos raquelalvarezbanos added State: In Progress Patch Candidate Urgent issues that must be included in a patch following a release labels Feb 21, 2017
@raquelalvarezbanos raquelalvarezbanos added this to the Release 3.10 milestone Feb 21, 2017
@dtasev dtasev self-assigned this Feb 23, 2017
@dtasev dtasev self-requested a review February 23, 2017 16:37
@@ -176,6 +176,9 @@ operator==(const TimeSeriesProperty<TYPE> &right) const {
{ // so vectors can go out of scope
std::vector<DateAndTime> lhsTimes = this->timesAsVector();
std::vector<DateAndTime> rhsTimes = right.timesAsVector();
if (lhsTimes.size() != rhsTimes.size()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you use TimeSeriesProperty::size() or TimeSeriesProperty::realSize() and copy the vectors if they aren't equal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 maybe extend the if (this->m_size != right.m_size) above with an || this->realSize() != right.realSize(), then the check will be applied for both below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The greatest effect would be had by putting this as an if on line 176.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterfpeterson Could you tell me why an additional if is preferred to extending an existing one?

Copy link
Contributor Author

@raquelalvarezbanos raquelalvarezbanos Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't they be the same? I've just added the additional because I find it easier to read.

@dtasev
Copy link
Contributor

dtasev commented Feb 24, 2017

I've tested without the fix and mantid crashes. After applying the fix there is no crash.
I've ran the unit tests without the fix and the new test fails. After applying the fix it passes successfully.
If @peterfpeterson doesn't have any comments I'm happy to :shipit:

if (this->realSize() != right.realSize()) {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the word else here and I'm happy

@peterfpeterson
Copy link
Member

I think a clearer version of the code (with added const below) is:

if (this->realSize() != right.realSize()) {
     return false;
} else {
     const std::vector<DateAndTime> lhsTimes = this->timesAsVector();
      const std::vector<DateAndTime> rhsTimes = right.timesAsVector();
     if (!std::equal(lhsTimes.begin(), lhsTimes.end(), rhsTimes.begin())) {
       return false;
     }

     const std::vector<TYPE> lhsValues = this->valuesAsVector();
     const std::vector<TYPE> rhsValues = right.valuesAsVector();
     if (!std::equal(lhsValues.begin(), lhsValues.end(), rhsValues.begin())) {
       return false;
     }
}

return true;

I don't think the const buys anything since those functions return copies of the vectors. Without checking against a compiler, you can probably declare the various variables as const auto as well, but I don't think it really adds.

@martyngigg
Copy link
Member

Tests are the usual unrelated failures.

@martyngigg martyngigg self-assigned this Feb 27, 2017
@martyngigg martyngigg merged commit ec95769 into master Feb 27, 2017
martyngigg pushed a commit that referenced this pull request Feb 27, 2017
Re #18944 Fix the issue

(cherry picked from commit 8880396)

Re #18944 Added unit test

(cherry picked from commit 291847a)

Re #18944 Fix compiler warning about unused equality comparison result

(cherry picked from commit c8bb2ae)

Re #18944 Check size before getting times

(cherry picked from commit 429775d)

Re #18944 Adding else + const

(cherry picked from commit 7de6a22)

Add patch release note
@rosswhitfield rosswhitfield deleted the 18944_Fix_issue_in_TimeSeriesProperty branch March 31, 2017 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Patch Candidate Urgent issues that must be included in a patch following a release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix crash with OFFSPEC data
4 participants