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 a8b0fb6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Bug Fixes
- recursive directory creation with existing base #261
- ``FindADIOS.cmake``: reset on multiple calls #263
- ``SerialIOTest``: remove variable shadowing #262
- ADIOS1: memory violation in string attribute writes #269

Other
"""""
Expand Down
16 changes: 8 additions & 8 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 @@ -840,9 +840,9 @@ 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 = auxiliary::allocatePtr(Datatype::CHAR, v.length() + 1u);
strcpy((char*)values.get(), v.c_str());
break;
}
case DT::VEC_CHAR:
Expand Down Expand Up @@ -977,7 +977,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 +1053,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 a8b0fb6

Please sign in to comment.