View Issue Details

IDProjectCategoryView StatusLast Update
0001729OpenFOAMBugpublic2015-06-02 20:41
Reporterroenby Assigned Tohenry  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSUbuntuOS Version12.04
Summary0001729: Wrong behaviour when appending vector to vectorField?
DescriptionThis code:

vectorField test;
vector t1(1.0,2.0,3.0);
test.append(t1);
vector& t2 = test[0];
test.append(t2);
Info << "test = " << test << endl;

results in the following output:

test = 2((1 2 3) (0 2 3))

The first component of the appended vector is not appended correctly.
Steps To ReproduceSee code above.
TagsNo tags attached.

Activities

henry

2015-06-02 20:26

manager   ~0004880

What happens when you run this in valgrind? Does the behavior change if you use a copy rather than a reference:

vector t2 = test[0];

roenby

2015-06-02 20:32

reporter   ~0004881

vector t2 = test[0];

results in the expected behaviour:

test = 2{(1 2 3)}

Have not tried it with valgrind.

henry

2015-06-02 20:41

manager   ~0004882

The issue is that you are holding a reference to an element that will be copied when the list is resized, this is likely to corrupt the memory which valgrind will show. To avoid the problem hold a copy of rather than a reference to the data which will move.

Issue History

Date Modified Username Field Change
2015-06-02 20:21 roenby New Issue
2015-06-02 20:26 henry Note Added: 0004880
2015-06-02 20:32 roenby Note Added: 0004881
2015-06-02 20:41 henry Note Added: 0004882
2015-06-02 20:41 henry Status new => resolved
2015-06-02 20:41 henry Resolution open => fixed
2015-06-02 20:41 henry Assigned To => henry