Skip to content

Commit

Permalink
Fix String Attribute Writes
Browse files Browse the repository at this point in the history
Used invalid pointer to string array before.
  • Loading branch information
ax3l committed Jun 18, 2018
1 parent caba260 commit d5189ce
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/IO/ADIOS/ADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable,

Attribute att = Attribute(parameters.resource);

int nelems;
int nelems = 0;
switch( parameters.dtype )
{
using DT = Datatype;
Expand Down Expand Up @@ -841,8 +841,10 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable,
case DT::STRING:
{
using uptr = std::unique_ptr< void, std::function< void(void*) > >;
values = uptr(const_cast< char* >(att.get< std::string >().c_str()),
[](void*){ });
auto const & v = att.get< std::string >();
values = uptr(new char[v.length() + 1u],
[](void* ca){ delete [] (char*)ca; });
strcpy((char*)values.get(), v.c_str());
break;
}
case DT::VEC_CHAR:
Expand Down Expand Up @@ -977,7 +979,7 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable,
"",
getBP1DataType(parameters.dtype),
nelems,
values.get());
values.get()); // Invalid read of size 1 (could be in ADIOS itself?)
VERIFY(status == err_no_error, "Internal error: Failed to define ADIOS attribute by value");

if( parameters.dtype == Datatype::VEC_STRING )
Expand Down Expand Up @@ -1053,9 +1055,9 @@ ADIOS1IOHandlerImpl::readAttribute(Writable* writable,
attrname += "/";
attrname += parameters.name;

ADIOS_DATATYPES datatype;
int size;
void* data;
ADIOS_DATATYPES datatype = adios_unknown;
int size = 0;
void* data = nullptr;

int status;
status = adios_get_attr(f,
Expand Down

0 comments on commit d5189ce

Please sign in to comment.