This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 956 - Fixing move constructor of DenseStorage
Summary: Fixing move constructor of DenseStorage
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: x86 - 64-bit All
: Normal Crash
Assignee: Nobody
URL:
Whiteboard:
Keywords: crash
: 1157 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-02-16 11:34 UTC by Martin Drozdik
Modified: 2019-12-04 14:14 UTC (History)
5 users (show)



Attachments
Patch to the move constructor of DenseStorage (2.02 KB, patch)
2015-02-16 11:34 UTC, Martin Drozdik
drozdik.svk: review?
Details | Diff

Description Martin Drozdik 2015-02-16 11:34:35 UTC
Created attachment 546 [details]
Patch to the move constructor of DenseStorage

I noticed that the move constructor of DenseStorage does not ensure that the moved-from object is in a valid state.

Example: 

  #include <utility>
  #include <iostream>

  #include <eigen3/Eigen/Dense>

  int main()
  {
      const std::size_t n = 12;

      Eigen::MatrixXd source = Eigen::MatrixXd::Zero(n, n);
      Eigen::MatrixXd target = std::move(source);
      std::cout << source << std::endl;

      return 0;
  }

This program crashes on:
gcc version 4.9.2 (Ubuntu 4.9.2-0ubuntu1~14.04) 
passing the compiler flag -std=c++14

The reason is that Eigen::MatrixXd, as well as many other classes, are using DenseStorage to store their data. The move constructor of DenseStorage however has a bug. When DenseStorage A is moved into DenseStorage B, the data pointer of A is correctly set to nullptr, but the number of columns and number of rows is not.

According to the C++ standard, moved-from objects in the standard library 
"shall be placed in a valid but unspecified state." (http://stackoverflow.com/a/7028318/1097451) I believe that this is reasonable also for the Eigen library. I made a small patch and tested the above mentioned code. After applying the patch, the code correctly outputs nothing and does not crash.
Comment 1 Gael Guennebaud 2015-02-16 17:36:03 UTC
Thank you for the patch. Applied:

https://bitbucket.org/eigen/eigen/commits/6e3df5a173da/
Changeset:   6e3df5a173da
User:        martin_drozdik
Date:        2015-02-16 09:18:46+00:00
Summary:     Bug 956: Fixed bug in move constructors of DenseStorage which caused "moved-from" objects to be in an invalid state.
Comment 2 Christoph Hertzberg 2016-01-27 00:06:21 UTC
*** Bug 1157 has been marked as a duplicate of this bug. ***
Comment 3 Nobody 2019-12-04 14:14:49 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/956.

Note You need to log in before you can comment on or make changes to this bug.