reformat with clang-format

This commit is contained in:
Axel Kohlmeyer
2021-08-06 08:39:32 -04:00
parent 8baaed5724
commit aeef6e6773

View File

@ -1,4 +1,3 @@
// clang-format off
/*----------------------------------------------------------------------
PuReMD - Purdue ReaxFF Molecular Dynamics Program
@ -35,69 +34,81 @@
namespace ReaxFF {
/* safe malloc */
void *smalloc(LAMMPS_NS::Error *error_ptr, rc_bigint n, const std::string &name)
{
void *ptr;
/* safe malloc */
void *smalloc(LAMMPS_NS::Error *error_ptr, rc_bigint n, const std::string &name)
{
void *ptr;
if (n <= 0) {
auto errmsg = fmt::format("Invalid size {} for array {}. Returning NULL.", n, name);
if (error_ptr) error_ptr->one(FLERR,errmsg);
else fputs(errmsg.c_str(),stderr);
if (n <= 0) {
auto errmsg = fmt::format("Invalid size {} for array {}. Returning NULL.", n, name);
if (error_ptr)
error_ptr->one(FLERR, errmsg);
else
fputs(errmsg.c_str(), stderr);
return nullptr;
}
ptr = malloc(n);
if (ptr == nullptr) {
auto errmsg = fmt::format("Failed to allocate {} bytes for array {}", n, name);
if (error_ptr) error_ptr->one(FLERR,errmsg);
else fputs(errmsg.c_str(),stderr);
}
return ptr;
return nullptr;
}
/* safe calloc */
void *scalloc(LAMMPS_NS::Error *error_ptr, rc_bigint n, rc_bigint size, const std::string &name)
{
void *ptr;
if (n <= 0) {
auto errmsg = fmt::format("Invalid size {} for array {}. Returning NULL.\n", n, name);
if (error_ptr) error_ptr->one(FLERR,errmsg);
else fputs(errmsg.c_str(),stderr);
return nullptr;
}
if (size <= 0) {
auto errmsg = fmt::format("Elements size for array {} is {}. Returning NULL", name, size);
if (error_ptr) error_ptr->one(FLERR,errmsg);
else fputs(errmsg.c_str(),stderr);
return nullptr;
}
ptr = calloc(n, size);
if (ptr == nullptr) {
auto errmsg = fmt::format("Failed to allocate {} bytes for array {}", n*size, name);
if (error_ptr) error_ptr->one(FLERR,errmsg);
else fputs(errmsg.c_str(),stderr);
}
return ptr;
ptr = malloc(n);
if (ptr == nullptr) {
auto errmsg = fmt::format("Failed to allocate {} bytes for array {}", n, name);
if (error_ptr)
error_ptr->one(FLERR, errmsg);
else
fputs(errmsg.c_str(), stderr);
}
/* safe free */
void sfree(LAMMPS_NS::Error *error_ptr, void *ptr, const std::string &name)
{
if (ptr == nullptr) {
auto errmsg = std::string("Trying to free the already free()'d pointer: ") + name;
if (error_ptr) error_ptr->one(FLERR, errmsg);
else fputs(errmsg.c_str(),stderr);
return;
}
free(ptr);
ptr = nullptr;
}
return ptr;
}
/* safe calloc */
void *scalloc(LAMMPS_NS::Error *error_ptr, rc_bigint n, rc_bigint size, const std::string &name)
{
void *ptr;
if (n <= 0) {
auto errmsg = fmt::format("Invalid size {} for array {}. Returning NULL.\n", n, name);
if (error_ptr)
error_ptr->one(FLERR, errmsg);
else
fputs(errmsg.c_str(), stderr);
return nullptr;
}
if (size <= 0) {
auto errmsg = fmt::format("Elements size for array {} is {}. Returning NULL", name, size);
if (error_ptr)
error_ptr->one(FLERR, errmsg);
else
fputs(errmsg.c_str(), stderr);
return nullptr;
}
ptr = calloc(n, size);
if (ptr == nullptr) {
auto errmsg = fmt::format("Failed to allocate {} bytes for array {}", n * size, name);
if (error_ptr)
error_ptr->one(FLERR, errmsg);
else
fputs(errmsg.c_str(), stderr);
}
return ptr;
}
/* safe free */
void sfree(LAMMPS_NS::Error *error_ptr, void *ptr, const std::string &name)
{
if (ptr == nullptr) {
auto errmsg = std::string("Trying to free the already free()'d pointer: ") + name;
if (error_ptr)
error_ptr->one(FLERR, errmsg);
else
fputs(errmsg.c_str(), stderr);
return;
}
free(ptr);
ptr = nullptr;
}
} // namespace ReaxFF