Fix address arithmetic in MemoryManager_ref_assignment.cpp and add unit test. refs #224

This commit is contained in:
John M. Penn 2016-04-15 14:34:38 -05:00 committed by Alex Lin
parent a00b5dc847
commit 5166946144
3 changed files with 49 additions and 7 deletions

View File

@ -265,12 +265,12 @@ int Trick::MemoryManager::assign_recursive(void* base_addr, ATTRIBUTES* attr, in
} else if ( remaining_dimensions > 0 ) {
int size_of_curr_dim;
size_of_curr_dim = attr->index[curr_dim].size ;
assign_addr = (char*)base_addr + offset * sizeof(void*);
int size_of_curr_dim = attr->index[curr_dim].size ;
if ( size_of_curr_dim == 0) { // the remaining dimensions are pointer dimensions.
assign_addr = (char*)base_addr + offset * sizeof(void*);
if (v_tree && v_tree->v_data) {
if ((remaining_dimensions == 1) && (v_tree->v_data->type == TRICK_STRING)) {
@ -297,6 +297,8 @@ int Trick::MemoryManager::assign_recursive(void* base_addr, ATTRIBUTES* attr, in
(v_tree->v_data)
) {
assign_addr = (char*)base_addr + offset * size_of_curr_dim * sizeof(char);
if ((v_tree->v_data->type == TRICK_STRING) &&
(v_tree->v_data->value.cp != NULL)) {
@ -310,10 +312,12 @@ int Trick::MemoryManager::assign_recursive(void* base_addr, ATTRIBUTES* attr, in
} else {
*(char*)assign_addr = '\0';
}
} else if ( (attr->type == TRICK_WCHAR) &&
(remaining_dimensions == 1)) {
assign_addr = (char*)base_addr + offset * size_of_curr_dim * sizeof(wchar_t);
if ((v_tree) &&
(v_tree->v_data->type == TRICK_WSTRING) &&
(v_tree->v_data->value.wcp != NULL)) {
@ -345,7 +349,7 @@ int Trick::MemoryManager::assign_recursive(void* base_addr, ATTRIBUTES* attr, in
} else {
*(wchar_t*)assign_addr = (wchar_t) NULL;
}
} else {
int ii;
V_TREE* curr_vt_node;
@ -353,7 +357,7 @@ int Trick::MemoryManager::assign_recursive(void* base_addr, ATTRIBUTES* attr, in
curr_vt_node = v_tree->down;
} else {
curr_vt_node = NULL;
}
}
for (ii=0; ii < size_of_curr_dim; ii++) {
int ret;

View File

@ -4,6 +4,7 @@
#include "MM_user_defined_types.hh"
#include "MM_test.hh"
#include <iostream>
#include <iomanip>
/*
@ -235,3 +236,34 @@ TEST_F(MM_read_checkpoint, bool_test) {
EXPECT_EQ( T_flag, true);
EXPECT_EQ( F_flag, false);
}
TEST_F(MM_read_checkpoint, 2D_char_array) {
UDT7 *udt7_p = (UDT7*)memmgr->declare_var("UDT7 udt7");
memmgr->set_debug_level(1);
memmgr->read_checkpoint_from_string(
"udt7.A = {"
"\"A00\",\"A01\",\"A02\",\"A03\",\"A04\",\"A05\",\"A06\",\"A07\","
"\"A08\",\"A09\",\"A10\",\"A11\",\"A12\",\"A13\",\"A14\",\"A15\","
"\"A16\",\"A17\",\"A18\",\"A19\",\"A20\",\"A21\",\"A22\",\"A23\","
"\"A24\",\"A25\",\"A26\",\"A27\",\"A28\",\"A29\",\"A30\",\"A31\"};"
);
for (int ii=0; ii<32; ii++) {
std::stringstream ss;
ss << "A" ;
ss << std::setfill('0') << std::setw(2) ;
ss << ii ;
std::cout << ss.str() << std::endl;
int result = ss.str().compare( &udt7_p->A[ii][0] );
EXPECT_EQ(result, 0);
}
}

View File

@ -87,3 +87,9 @@ class UDT4 : public UDT3 {
double XX;
};
class UDT7 {
public:
char A[32][4];
char B[32][4];
};