Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressing static analysis from coverity scan #511

Merged
merged 2 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bindings/C/adios2/adios2_c_adios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#include "adios2_c_adios.h"
#include "adios2/ADIOSMPI.h"
#include "adios2/core/ADIOS.h"
#include "adios2/helper/adiosFunctions.h"

adios2_adios *adios2_init_config(const char *config_file, MPI_Comm mpi_comm,
const adios2_debug_mode debug_mode)
{
adios2::CheckForNullptr(config_file,
"for config_file, in call to adios2_init_config");
const bool debugBool = (debug_mode == adios2_debug_mode_on) ? true : false;
adios2_adios *adios = reinterpret_cast<adios2_adios *>(
new adios2::ADIOS(config_file, mpi_comm, debugBool, "C"));
Expand All @@ -40,17 +43,23 @@ adios2_adios *adios2_init_nompi(const adios2_debug_mode debug_mode)

adios2_io *adios2_declare_io(adios2_adios *adios, const char *ioName)
{
adios2::CheckForNullptr(adios,
"for adios2_adios, in call to adios2_declare_io");
adios2_io *io = reinterpret_cast<adios2_io *>(
&reinterpret_cast<adios2::ADIOS *>(adios)->DeclareIO(ioName));
return io;
}

void adios2_flush_all(adios2_adios *adios)
{
adios2::CheckForNullptr(adios,
"for adios2_adios, in call to adios2_flush_all");
reinterpret_cast<adios2::ADIOS *>(adios)->FlushAll();
}

void adios2_finalize(adios2_adios *adios)
{
adios2::CheckForNullptr(adios,
"for adios2_adios, in call to adios2_finalize");
delete reinterpret_cast<adios2::ADIOS *>(adios);
}
86 changes: 86 additions & 0 deletions bindings/C/adios2/adios2_c_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ adios2_step_status adios2_begin_step(adios2_engine *engine,
const adios2_step_mode mode,
const float timeout_seconds)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_begin_step");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);

adios2::StepStatus statusCpp = adios2::StepStatus::OK;
Expand Down Expand Up @@ -70,6 +72,12 @@ adios2_step_status adios2_begin_step(adios2_engine *engine,
void adios2_put_sync(adios2_engine *engine, adios2_variable *variable,
const void *values)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_put_sync");

adios2::CheckForNullptr(variable,
"for adios2_variable, in call to adios2_put_sync");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -92,6 +100,12 @@ void adios2_put_sync(adios2_engine *engine, adios2_variable *variable,

void adios2_put_sync_self(adios2_engine *engine, adios2_variable *variable)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_put_sync_self");

adios2::CheckForNullptr(
variable, "for adios2_variable, in call to adios2_put_sync_self");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -114,6 +128,13 @@ void adios2_put_sync_self(adios2_engine *engine, adios2_variable *variable)
void adios2_put_sync_by_name(adios2_engine *engine, const char *variable_name,
const void *values)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_put_sync_by_name");

adios2::CheckForNullptr(
variable_name,
"for const char* variable_name, in call to adios2_put_sync_by_name");

auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
const std::string type(
engineCpp.GetIO().InquireVariableType(variable_name));
Expand All @@ -134,6 +155,12 @@ void adios2_put_sync_by_name(adios2_engine *engine, const char *variable_name,
void adios2_put_deferred(adios2_engine *engine, adios2_variable *variable,
const void *values)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_put_deferred");

adios2::CheckForNullptr(
variable, "for adios2_variable, in call to adios2_put_deferred");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -157,6 +184,12 @@ void adios2_put_deferred(adios2_engine *engine, adios2_variable *variable,

void adios2_put_deferred_self(adios2_engine *engine, adios2_variable *variable)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_put_deferred_self");

adios2::CheckForNullptr(
variable, "for adios2_variable, in call to adios2_put_deferred_self");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -180,6 +213,13 @@ void adios2_put_deferred_self(adios2_engine *engine, adios2_variable *variable)
void adios2_put_deferred_by_name(adios2_engine *engine,
const char *variable_name, const void *values)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_put_deferred_by_name");

adios2::CheckForNullptr(variable_name,
"for const char* variable_name, in call "
"to adios2_put_deferred_by_name");

auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
const std::string type(
engineCpp.GetIO().InquireVariableType(variable_name));
Expand All @@ -200,13 +240,20 @@ void adios2_put_deferred_by_name(adios2_engine *engine,

void adios2_perform_puts(adios2_engine *engine)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_perform_puts");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.PerformPuts();
}

void adios2_get_sync(adios2_engine *engine, adios2_variable *variable,
void *values)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_get_sync");
adios2::CheckForNullptr(variable, "for adios2_variable, in call "
"to adios2_get_sync");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -229,6 +276,11 @@ void adios2_get_sync(adios2_engine *engine, adios2_variable *variable,

void adios2_get_sync_self(adios2_engine *engine, adios2_variable *variable)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_get_sync_self");
adios2::CheckForNullptr(variable, "for adios2_variable, in call "
"to adios2_get_sync_self");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -251,6 +303,12 @@ void adios2_get_sync_self(adios2_engine *engine, adios2_variable *variable)
void adios2_get_sync_by_name(adios2_engine *engine, const char *variable_name,
void *values)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_get_sync_by_name");
adios2::CheckForNullptr(variable_name,
"for const char* variable_name, in call to "
"adios2_get_sync_by_name");

auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
const std::string type(
engineCpp.GetIO().InquireVariableType(variable_name));
Expand All @@ -271,6 +329,11 @@ void adios2_get_sync_by_name(adios2_engine *engine, const char *variable_name,
void adios2_get_deferred(adios2_engine *engine, adios2_variable *variable,
void *values)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_get_deferred");
adios2::CheckForNullptr(variable, "for adios2_variable, in call "
"to adios2_get_deferred");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -294,6 +357,11 @@ void adios2_get_deferred(adios2_engine *engine, adios2_variable *variable,

void adios2_get_deferred_self(adios2_engine *engine, adios2_variable *variable)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_get_deferred_self");
adios2::CheckForNullptr(variable, "for adios2_variable, in call "
"to adios2_get_deferred_self");

adios2::VariableBase *variableBase =
reinterpret_cast<adios2::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
Expand All @@ -317,6 +385,12 @@ void adios2_get_deferred_self(adios2_engine *engine, adios2_variable *variable)
void adios2_get_deferred_by_name(adios2_engine *engine,
const char *variable_name, void *values)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_get_deferred_by_name");
adios2::CheckForNullptr(variable_name,
"for const char* variable_name, in call "
"to adios2_get_deferred_by_name");

auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
const std::string type(
engineCpp.GetIO().InquireVariableType(variable_name));
Expand All @@ -336,37 +410,49 @@ void adios2_get_deferred_by_name(adios2_engine *engine,

void adios2_perform_gets(adios2_engine *engine)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_perform_gets");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.PerformGets();
}

void adios2_end_step(adios2_engine *engine)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_end_step");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.EndStep();
}

void adios2_write_step(adios2_engine *engine)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_write_step");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.WriteStep();
}

void adios2_flush(adios2_engine *engine)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_flush");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.Flush();
}

void adios2_close(adios2_engine *engine)
{
adios2::CheckForNullptr(engine,
"for adios2_engine, in call to adios2_close");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.Close();
}

void adios2_close_by_index(adios2_engine *engine,
const unsigned int transport_index)
{
adios2::CheckForNullptr(
engine, "for adios2_engine, in call to adios2_close_by_index");
auto &engineCpp = *reinterpret_cast<adios2::Engine *>(engine);
engineCpp.Close(transport_index);
}
34 changes: 34 additions & 0 deletions bindings/C/adios2/adios2_c_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ adios2_define_variable(adios2_io *io, const char *name, const adios2_type type,
const size_t *start, const size_t *count,
const adios2_constant_dims constant_dims, void *data)
{
adios2::CheckForNullptr(io,
"for adios2_io, in call to adios2_define_variable");

const bool constantSizeBool =
(constant_dims == adios2_constant_dims_true) ? true : false;

Expand Down Expand Up @@ -227,6 +230,9 @@ adios2_define_variable(adios2_io *io, const char *name, const adios2_type type,

adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_inquire_variable");

adios2::IO &ioCpp = *reinterpret_cast<adios2::IO *>(io);
const auto &dataMap = ioCpp.GetVariablesDataMap();

Expand Down Expand Up @@ -256,11 +262,17 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name)

int adios2_remove_variable(adios2_io *io, const char *name)
{
adios2::CheckForNullptr(io,
"for adios2_io, in call to adios2_remove_variable");

return (reinterpret_cast<adios2::IO *>(io)->RemoveVariable(name)) ? 1 : 0;
}

void adios2_remove_all_variables(adios2_io *io)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_remove_all_variables");

reinterpret_cast<adios2::IO *>(io)->RemoveAllVariables();
}

Expand All @@ -269,6 +281,12 @@ adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name,
const void *data,
const size_t elements)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_define_attribute");

adios2::CheckForNullptr(
data, "for const void* data, in call to adios2_define_attribute");

adios2::IO &ioCpp = *reinterpret_cast<adios2::IO *>(io);
adios2::AttributeBase *attribute = nullptr;

Expand Down Expand Up @@ -439,47 +457,61 @@ adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name,

int adios2_remove_attribute(adios2_io *io, const char *name)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_remove_attribute");
return (reinterpret_cast<adios2::IO *>(io)->RemoveAttribute(name)) ? 1 : 0;
}

void adios2_remove_all_attributes(adios2_io *io)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_remove_all_attributes");
reinterpret_cast<adios2::IO *>(io)->RemoveAllAttributes();
}

void adios2_set_engine(adios2_io *io, const char *engine_type)
{
adios2::CheckForNullptr(io, "for adios2_io, in call to adios2_set_engine");
reinterpret_cast<adios2::IO *>(io)->SetEngine(engine_type);
}

void adios2_set_parameter(adios2_io *io, const char *key, const char *value)
{
adios2::CheckForNullptr(io,
"for adios2_io, in call to adios2_set_parameter");
reinterpret_cast<adios2::IO *>(io)->SetParameter(key, value);
}

unsigned int adios2_add_transport(adios2_io *io, const char *transport_type)
{
adios2::CheckForNullptr(io,
"for adios2_io, in call to adios2_add_transport");
return reinterpret_cast<adios2::IO *>(io)->AddTransport(transport_type);
}

void adios2_set_transport_parameter(adios2_io *io,
const unsigned int transport_index,
const char *key, const char *value)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_set_transport_parameter");
reinterpret_cast<adios2::IO *>(io)->SetTransportParameter(transport_index,
key, value);
}

adios2_engine *adios2_open(adios2_io *io, const char *name,
const adios2_mode mode)
{
adios2::CheckForNullptr(io, "for adios2_io, in call to adios2_open");
auto &ioCpp = *reinterpret_cast<adios2::IO *>(io);
return adios2_open_new_comm(io, name, mode, ioCpp.m_MPIComm);
}

adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name,
const adios2_mode mode, MPI_Comm mpi_comm)
{
adios2::CheckForNullptr(io,
"for adios2_io, in call to adios2_open_new_comm");
auto &ioCpp = *reinterpret_cast<adios2::IO *>(io);
adios2::Engine *engine = nullptr;

Expand Down Expand Up @@ -508,5 +540,7 @@ adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name,

void adios2_flush_all_engines(adios2_io *io)
{
adios2::CheckForNullptr(
io, "for adios2_io, in call to adios2_flush_all_engines");
reinterpret_cast<adios2::IO *>(io)->FlushAll();
}
Loading