From 76b0c8e7b1da063c2d923ba678c00581d8abdb2a Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Sun, 17 Jun 2018 01:06:48 +0200 Subject: [PATCH] Fix String Attribute Writes Used invalid pointer to string array before. --- CHANGELOG.rst | 1 + src/IO/ADIOS/ADIOS1IOHandler.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f5743f8ed7..cf620cefe8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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: string attribute writes #269 Other """"" diff --git a/src/IO/ADIOS/ADIOS1IOHandler.cpp b/src/IO/ADIOS/ADIOS1IOHandler.cpp index 22cb823a91..c8a0bfa42f 100644 --- a/src/IO/ADIOS/ADIOS1IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS1IOHandler.cpp @@ -718,7 +718,7 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable, Attribute att = Attribute(parameters.resource); - int nelems; + int nelems = 0; switch( parameters.dtype ) { using DT = Datatype; @@ -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: @@ -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 ) @@ -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,