diff --git a/trick_source/sim_services/VariableServer/VariableReference.cpp b/trick_source/sim_services/VariableServer/VariableReference.cpp index 4329dbe0..b9097cbd 100644 --- a/trick_source/sim_services/VariableServer/VariableReference.cpp +++ b/trick_source/sim_services/VariableServer/VariableReference.cpp @@ -5,6 +5,8 @@ #include // for setprecision #include #include +#include +#include #include "trick/VariableReference.hh" #include "trick/memorymanager_c_intf.h" @@ -17,6 +19,7 @@ #include "trick/trick_byteswap.h" + // Static variables to be addresses that are known to be the error ref address int Trick::VariableReference::_bad_ref_int = 0 ; int Trick::VariableReference::_do_not_resolve_bad_ref_int = 0 ; @@ -84,6 +87,7 @@ Trick::VariableReference::VariableReference(std::string var_name, double* time) _base_units = _var_info->attr->units; _requested_units = "s"; _name = _var_info->reference; + } Trick::VariableReference::VariableReference(std::string var_name) : _staged(false), _write_ready(false) { @@ -282,6 +286,7 @@ int Trick::VariableReference::setRequestedUnits(std::string units_name) { int Trick::VariableReference::stageValue(bool validate_address) { _write_ready = false; + std::string *str_ptr = NULL; // Copy bytes from
to staging_point. @@ -309,7 +314,7 @@ int Trick::VariableReference::stageValue(bool validate_address) { // if this variable is a string we need to get the raw character string out of it. if (( _trick_type == TRICK_STRING ) && !_deref) { - std::string * str_ptr = (std::string *)_var_info->address ; + str_ptr = (std::string *)_var_info->address ; // Get a pointer to the internal character array _address = (void *)(str_ptr->c_str()) ; } @@ -320,11 +325,16 @@ int Trick::VariableReference::stageValue(bool validate_address) { } // handle c++ string and char* - if ( _trick_type == TRICK_STRING ) { + if ( _trick_type == TRICK_STRING ){ + if (_address == NULL) { _size = 0 ; - } else { - _size = strlen((char*)_address) + 1 ; + } else { + //_size = strlen((char*)_address) + 1 ; + _size = (int )str_ptr->size(); + if (_size <= 0 || _size > 4096) { + _size = 0; + } } } // handle c++ wstring and wchar_t* @@ -336,7 +346,11 @@ int Trick::VariableReference::stageValue(bool validate_address) { } } if(_address != NULL) { - memcpy( _stage_buffer , _address , _size ) ; + if (_trick_type == TRICK_STRING ) { + str_ptr->copy((char*)_stage_buffer,_size,0); + } else { + memcpy( _stage_buffer , _address , _size ) ; + } } _staged = true; @@ -734,4 +748,4 @@ int Trick::VariableReference::writeValueBinary( std::ostream& out, bool byteswap std::ostream& Trick::operator<< (std::ostream& s, const Trick::VariableReference& ref) { s << " \"" << ref.getName() << "\""; return s; -} \ No newline at end of file +} diff --git a/trick_source/sim_services/VariableServer/VariableServerSession_commands.cpp b/trick_source/sim_services/VariableServer/VariableServerSession_commands.cpp index 1c09db39..4a899c25 100644 --- a/trick_source/sim_services/VariableServer/VariableServerSession_commands.cpp +++ b/trick_source/sim_services/VariableServer/VariableServerSession_commands.cpp @@ -23,6 +23,8 @@ int Trick::VariableServerSession::var_add(std::string in_name) { new_var = new VariableReference(in_name, &_time); } else { new_var = new VariableReference(in_name); + ALLOC_INFO * allocOf = get_alloc_info_of(new_var._address); + ALLOC_INFO * allocAt = get_alloc_info_at(new_var._address); } _session_variables.push_back(new_var) ;