This bugzilla service is closed. All entries have been migrated to
Bug 956 - Fixing move constructor of DenseStorage
Summary: Fixing move constructor of DenseStorage
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
Keywords: crash
: 1157 (view as bug list)
Depends on:
Reported: 2015-02-16 11:34 UTC by Martin Drozdik
Modified: 2019-12-04 14:14 UTC (History)
5 users (show)

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.


  #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." ( 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:
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'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:

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