Warn for type mismatch for gmx printf like functions 3/3
authorRoland Schulz <roland.schulz@intel.com>
Sat, 14 Jul 2018 05:57:53 +0000 (22:57 -0700)
committerRoland Schulz <roland.schulz@intel.com>
Fri, 14 Sep 2018 02:30:18 +0000 (19:30 -0700)
Add attributes for gcc (and compatible) and msvc.
And fix remaining issues.

Related #2570

Change-Id: I9b46559c2554404b309aa8710eb34ffa128d8cae

33 files changed:
src/gromacs/awh/bias.cpp
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec_setup.cpp
src/gromacs/essentialdynamics/edsam.cpp
src/gromacs/ewald/tests/pmesplinespreadtest.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxana/gmx_hydorder.cpp
src/gromacs/gmxana/gmx_make_edi.cpp
src/gromacs/gmxlib/network.cpp
src/gromacs/gmxlib/network.h
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/gmxpreprocess/toputil.cpp
src/gromacs/gpu_utils/cudautils.cuh
src/gromacs/gpu_utils/gpu_utils.cu
src/gromacs/gpu_utils/gpu_utils_ocl.cpp
src/gromacs/hardware/printhardware.cpp
src/gromacs/listed-forces/manage-threading.cpp
src/gromacs/mdlib/lincs.cpp
src/gromacs/mdlib/nbnxn_ocl/nbnxn_ocl.cpp
src/gromacs/mdlib/nbnxn_search.cpp
src/gromacs/mdlib/nbnxn_tuning.cpp
src/gromacs/mdlib/shellfc.cpp
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/runner.cpp
src/gromacs/pulling/pull.cpp
src/gromacs/selection/selmethod.cpp
src/gromacs/tables/splineutil.cpp
src/gromacs/utility/fatalerror.cpp
src/gromacs/utility/fatalerror.h
src/gromacs/utility/logger.cpp
src/gromacs/utility/logger.h
src/gromacs/utility/stringutil.cpp
src/gromacs/utility/stringutil.h

index bde1a68fbeac4416386f3092cc8e74157c42763d..437784e24d3c4c760af9f068ffec1cbf4c7face9 100644 (file)
@@ -47,6 +47,7 @@
 #include "bias.h"
 
 #include <cassert>
+#include <cinttypes>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
@@ -242,7 +243,7 @@ static void ensureStateAndRunConsistency(const BiasParams &params,
     int64_t numUpdatesExpected    = state.histogramSize().numUpdates();
     if (numUpdatesFromSamples != numUpdatesExpected)
     {
-        std::string mesg = gmx::formatString("The number of AWH updates in the checkpoint file (%ld) does not match the total number of AWH samples divided by the number of samples per update for %d sharing AWH bias(es) (%ld/%d=%ld)",
+        std::string mesg = gmx::formatString("The number of AWH updates in the checkpoint file (%" PRId64 ") does not match the total number of AWH samples divided by the number of samples per update for %d sharing AWH bias(es) (%" PRId64 "/%d=%" PRId64 ")",
                                              numUpdatesExpected,
                                              params.numSharedUpdate,
                                              numSamples,
@@ -255,7 +256,7 @@ static void ensureStateAndRunConsistency(const BiasParams &params,
          */
         if (numUpdatesFromSamples % state.histogramSize().numUpdates() == 0)
         {
-            mesg += gmx::formatString(" Or the run you continued from used %ld sharing simulations, whereas you now specified %d sharing simulations.",
+            mesg += gmx::formatString(" Or the run you continued from used %" PRId64 " sharing simulations, whereas you now specified %d sharing simulations.",
                                       numUpdatesFromSamples/state.histogramSize().numUpdates(),
                                       params.numSharedUpdate);
         }
index 3e1bd81c8c99191c7d85034b472f5a86c8bad66d..d9f565e980518b6adbaef501206120910bed2966 100644 (file)
@@ -40,6 +40,7 @@
 #include "config.h"
 
 #include <cassert>
+#include <cinttypes>
 #include <climits>
 #include <cmath>
 #include <cstdio>
@@ -3399,7 +3400,7 @@ static DlbState determineInitialDlbState(const gmx::MDLogger &mdlog,
             case DlbState::onUser:
                 return forceDlbOffOrBail(dlbState, reasonStr + " In load balanced runs binary reproducibility cannot be ensured.", mdlog);
             default:
-                gmx_fatal(FARGS, "Death horror: undefined case (%d) for load balancing choice", dlbState);
+                gmx_fatal(FARGS, "Death horror: undefined case (%d) for load balancing choice", static_cast<int>(dlbState));
         }
     }
 
@@ -6451,7 +6452,7 @@ void dd_partition_system(FILE                *fplog,
     {
         if (state_local->ddp_count > dd->ddp_count)
         {
-            gmx_fatal(FARGS, "Internal inconsistency state_local->ddp_count (%d) > dd->ddp_count (%ld)", state_local->ddp_count, dd->ddp_count);
+            gmx_fatal(FARGS, "Internal inconsistency state_local->ddp_count (%d) > dd->ddp_count (%" PRId64 ")", state_local->ddp_count, dd->ddp_count);
         }
 
         if (state_local->ddp_count_cg_gl != state_local->ddp_count)
index 568c948d6597ed76a083fc4321a587f8cc1a9fda..8df4070901231fdd9978b004d07594d9ed81eeba 100644 (file)
@@ -45,6 +45,7 @@
 #include "gmxpre.h"
 
 #include <cassert>
+#include <cinttypes>
 #include <cmath>
 #include <cstdio>
 
@@ -760,7 +761,7 @@ real dd_choose_grid(const gmx::MDLogger &mdlog,
             /* Check if the largest divisor is more than nnodes^2/3 */
             if (ldiv*ldiv*ldiv > nnodes_div*nnodes_div)
             {
-                gmx_fatal(FARGS, "The number of ranks you selected (%ld) contains a large prime factor %ld. In most cases this will lead to bad performance. Choose a number with smaller prime factors or set the decomposition (option -dd) manually.",
+                gmx_fatal(FARGS, "The number of ranks you selected (%" PRId64 ") contains a large prime factor %" PRId64 ". In most cases this will lead to bad performance. Choose a number with smaller prime factors or set the decomposition (option -dd) manually.",
                           nnodes_div, ldiv);
             }
         }
index 4e881bfcdc2ca90aaa8b6fd6039687c8e6f20c75..db1b4d12de9b6a7bc4862ccb470d3d6a476b1141 100644 (file)
@@ -2363,7 +2363,7 @@ static void crosscheck_edi_file_vs_checkpoint(const gmx_edsam &ed, edsamhistory_
     if (static_cast<int>(ed.edpar.size()) != EDstate->nED)
     {
         gmx_fatal(FARGS, "The number of essential dynamics / flooding groups is not consistent.\n"
-                  "There are %d ED groups in the .cpt file, but %d in the .edi file!\n"
+                  "There are %d ED groups in the .cpt file, but %zu in the .edi file!\n"
                   "Are you sure this is the correct .edi file?\n", EDstate->nED, ed.edpar.size());
     }
 }
index 43c4b02852c4c006cc4cfc920fbeca94bce7d5de..3e593791bf8a16cfdf9f2e100da019d0141bd6e3 100644 (file)
@@ -179,7 +179,7 @@ class PmeSplineAndSpreadTest : public ::testing::TestWithParam<SplineAndSpreadIn
                         const char *dimString[] = { "X", "Y", "Z" };
 
                         /* Spline values */
-                        SCOPED_TRACE(formatString("Testing spline values with tolerance of %ld", ulpToleranceSplineValues));
+                        SCOPED_TRACE(formatString("Testing spline values with tolerance of %d", ulpToleranceSplineValues));
                         TestReferenceChecker splineValuesChecker(rootChecker.checkCompound("Splines", "Values"));
                         splineValuesChecker.setDefaultTolerance(relativeToleranceAsUlp(1.0, ulpToleranceSplineValues));
                         for (int i = 0; i < DIM; i++)
@@ -191,7 +191,7 @@ class PmeSplineAndSpreadTest : public ::testing::TestWithParam<SplineAndSpreadIn
                         /* Spline derivatives */
                         const auto ulpToleranceSplineDerivatives = 4 * ulpToleranceSplineValues;
                         /* 4 is just a wild guess since the derivatives are deltas of neighbor spline values which could differ greatly */
-                        SCOPED_TRACE(formatString("Testing spline derivatives with tolerance of %ld", ulpToleranceSplineDerivatives));
+                        SCOPED_TRACE(formatString("Testing spline derivatives with tolerance of %d", ulpToleranceSplineDerivatives));
                         TestReferenceChecker splineDerivativesChecker(rootChecker.checkCompound("Splines", "Derivatives"));
                         splineDerivativesChecker.setDefaultTolerance(relativeToleranceAsUlp(1.0, ulpToleranceSplineDerivatives));
                         for (int i = 0; i < DIM; i++)
@@ -212,7 +212,7 @@ class PmeSplineAndSpreadTest : public ::testing::TestWithParam<SplineAndSpreadIn
                         TestReferenceChecker       gridValuesChecker(rootChecker.checkCompound("NonZeroGridValues", "RealSpaceGrid"));
                         const auto                 ulpToleranceGrid = 2 * ulpToleranceSplineValues * static_cast<int>(ceil(sqrt(atomCount)));
                         /* 2 is empiric; sqrt(atomCount) assumes all the input charges may spread onto the same cell */
-                        SCOPED_TRACE(formatString("Testing grid values with tolerance of %ld", ulpToleranceGrid));
+                        SCOPED_TRACE(formatString("Testing grid values with tolerance of %d", ulpToleranceGrid));
                         if (!gridValuesSizeAssigned)
                         {
                             previousGridValuesSize = nonZeroGridValues.size();
index fa44d4ed05b62be066f5a88bf8d1724108d6532f..364bddea2164afbd740d7645dd959b9383421fb7 100644 (file)
@@ -2599,7 +2599,7 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx,
         if ((precision != sizeof(float)) && !bDouble)
         {
             gmx_fatal(FARGS, "Unknown precision in file %s: real is %d bytes "
-                      "instead of %lu or %lu",
+                      "instead of %zu or %zu",
                       gmx_fio_getname(fio), precision, sizeof(float), sizeof(double));
         }
         gmx_fio_setprecision(fio, bDouble);
index 4fe52c384e4ab402c07d95842dccdd8f952fd55e..403fd5ae95227457466d9a2fb78923905721797a 100644 (file)
@@ -665,7 +665,7 @@ int gmx_hydorder(int argc, char *argv[])
     gmx::ArrayRef<const std::string> intfn = opt2fns("-o", NFILE, fnm);
     if (intfn.size() != 2)
     {
-        gmx_fatal(FARGS, "No or not correct number (2) of output-files: %ld", intfn.size());
+        gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.size());
     }
     calc_tetra_order_interface(ndxfnm, tpsfnm, trxfnm, binwidth, nsttblock, &frames, &xslices, &yslices, sg1, sg2, &intfpos, oenv);
     writesurftoxpms(intfpos, frames, xslices, yslices, binwidth, intfn, nlevels);
@@ -675,7 +675,7 @@ int gmx_hydorder(int argc, char *argv[])
         gmx::ArrayRef<const std::string> spectra = opt2fns("-Spect", NFILE, fnm);
         if (spectra.size() != 2)
         {
-            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %ld", spectra.size());
+            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.size());
         }
         powerspectavg(intfpos, frames, xslices, yslices, spectra);
     }
@@ -685,7 +685,7 @@ int gmx_hydorder(int argc, char *argv[])
         gmx::ArrayRef<const std::string> raw = opt2fns("-or", NFILE, fnm);
         if (raw.size() != 2)
         {
-            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %ld", raw.size());
+            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.size());
         }
         writeraw(intfpos, frames, xslices, yslices, raw);
     }
index 77d361396d57ad05d0041c80d18022915d12201f..1e9608e3ec6d2a40fbc3a2344600d37ecc7d4599 100644 (file)
@@ -291,12 +291,12 @@ static int sscan_list(int *list[], const char *str, const char *listname)
 
             /* format error occured */
             case sError:
-                gmx_fatal(FARGS, "Error in the list of eigenvectors for %s at pos %ld with char %c", listname, pos-startpos, *(pos-1));
+                gmx_fatal(FARGS, "Error in the list of eigenvectors for %s at pos %td with char %c", listname, pos-startpos, *(pos-1));
             /* logical error occured */
             case sZero:
-                gmx_fatal(FARGS, "Error in the list of eigenvectors for %s at pos %ld: eigenvector 0 is not valid", listname, pos-startpos);
+                gmx_fatal(FARGS, "Error in the list of eigenvectors for %s at pos %td: eigenvector 0 is not valid", listname, pos-startpos);
             case sSmaller:
-                gmx_fatal(FARGS, "Error in the list of eigenvectors for %s at pos %ld: second index %d is not bigger than %d", listname, pos-startpos, end_number, number);
+                gmx_fatal(FARGS, "Error in the list of eigenvectors for %s at pos %td: second index %d is not bigger than %d", listname, pos-startpos, end_number, number);
         }
         ++pos; /* read next character */
     }          /*scanner has finished */
index 41f6826ba27bf1f53ccbc1081d473bdee8799f53..9276f5a444a83fb0d147ac4baeb28e22a26fbf25 100644 (file)
@@ -756,7 +756,7 @@ const char *opt2fn_master(const char *opt, int nfile, const t_filenm fnm[],
 
 void gmx_fatal_collective(int f_errno, const char *file, int line,
                           MPI_Comm comm, gmx_bool bMaster,
-                          const char *fmt, ...)
+                          gmx_fmtstr const char *fmt, ...)
 {
     va_list  ap;
     gmx_bool bFinalize;
index 233d64c46938a5b6e544be315fc0bfd5bcf2a4c2..5919aff4373df4beedeea4c6c389b83e0321e2e7 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/gmxmpi.h"
+#include "gromacs/utility/stringutil.h"
 
 struct gmx_multisim_t;
 struct t_commrec;
@@ -131,7 +132,7 @@ const char *opt2fn_master(const char *opt, int nfile,
 [[ noreturn ]] void
 gmx_fatal_collective(int f_errno, const char *file, int line,
                      MPI_Comm comm, gmx_bool bMaster,
-                     const char *fmt, ...);
+                     gmx_fmtstr const char *fmt, ...) gmx_format(printf, 6, 7);
 /* As gmx_fatal declared in utility/fatalerror.h,
  * but only the master process prints the error message.
  * This should only be called one of the following two situations:
index b27b707f1bc93c3b9e968244fdf88909b6e92493..355b112447679f887af7936470de74a9e678ae0c 100644 (file)
@@ -3493,7 +3493,7 @@ void do_index(const char* mdparin, const char *ndx,
     auto accelerationGroupNames = gmx::splitString(is->accgrps);
     if (accelerationGroupNames.size() * DIM != accelerations.size())
     {
-        gmx_fatal(FARGS, "Invalid Acceleration input: %d groups and %d acc. values",
+        gmx_fatal(FARGS, "Invalid Acceleration input: %zu groups and %zu acc. values",
                   accelerationGroupNames.size(), accelerations.size());
     }
     do_numbering(natoms, groups, accelerationGroupNames, grps, gnames, egcACC,
@@ -3508,7 +3508,7 @@ void do_index(const char* mdparin, const char *ndx,
     auto freezeGroupNames = gmx::splitString(is->freeze);
     if (freezeDims.size() != DIM * freezeGroupNames.size())
     {
-        gmx_fatal(FARGS, "Invalid Freezing input: %d groups and %d freeze values",
+        gmx_fatal(FARGS, "Invalid Freezing input: %zu groups and %zu freeze values",
                   freezeGroupNames.size(), freezeDims.size());
     }
     do_numbering(natoms, groups, freezeGroupNames, grps, gnames, egcFREEZE,
index 8a66e7bf73b79ed2217b1472e711e2630b459715..96a183e863eb8864db1d9d72eaf47e1d900670f9 100644 (file)
@@ -66,7 +66,7 @@ void set_p_string(t_param *p, const char *s)
         }
         else
         {
-            gmx_fatal(FARGS, "Increase MAXSLEN in the grompp code to at least %lu,"
+            gmx_fatal(FARGS, "Increase MAXSLEN in the grompp code to at least %zu,"
                       " or shorten your definition of bonds like %s to at most %d",
                       strlen(s)+1, s, MAXSLEN-1);
         }
index 6eabc3ce145d2403295fec220e47c8f3ea825c2e..dac92fa6fe70b45a40e838aef682cd5cf8c268a5 100644 (file)
@@ -85,7 +85,7 @@ static inline void ensureNoPendingCudaError(const char *errorMessage)
     GMX_ASSERT(stat == cudaSuccess, fullMessage.c_str());
     // TODO When we evolve a better logging framework, use that
     // for release-build error reporting.
-    gmx_warning(fullMessage.c_str());
+    gmx_warning("%s", fullMessage.c_str());
 }
 
 }   // namespace
index 107d90fb31830b04679a55ffbad9718f7fd7b928..15e467308f66bac62766e66a7bdde3f68bbc7cd1 100644 (file)
@@ -117,8 +117,8 @@ static void checkCompiledTargetCompatibility(const gmx_device_info_t *devInfo)
                   "The %s binary does not include support for the CUDA architecture "
                   "of the selected GPU (device ID #%d, compute capability %d.%d). "
                   "By default, GROMACS supports all common architectures, so your GPU "
-                  "might be rare, or some architectures were disabled in the build. ",
-                  "Consult the install guide for how to use the GMX_CUDA_TARGET_SM and ",
+                  "might be rare, or some architectures were disabled in the build. "
+                  "Consult the install guide for how to use the GMX_CUDA_TARGET_SM and "
                   "GMX_CUDA_TARGET_COMPUTE CMake variables to add this architecture.",
                   gmx::getProgramContext().displayName(), devInfo->id,
                   devInfo->prop.major, devInfo->prop.minor);
@@ -757,8 +757,8 @@ void findGpus(gmx_gpu_info_t *gpu_info)
             // errors during sanity checks don't propagate.
             if ((stat = cudaGetLastError()) != cudaSuccess)
             {
-                gmx_warning(gmx::formatString("An error occurred while sanity checking device #%d; %s: %s",
-                                              devs[i].id, cudaGetErrorName(stat), cudaGetErrorString(stat)).c_str());
+                gmx_warning("An error occurred while sanity checking device #%d; %s: %s",
+                            devs[i].id, cudaGetErrorName(stat), cudaGetErrorString(stat));
             }
         }
     }
index ea8451fb2ed2c97d2f375af1403ba8fe9ff3d16d..1936cc5937aad0f44131623a9eb37bd7e76433ae 100644 (file)
@@ -167,7 +167,7 @@ bool canDetectGpus(std::string *errorMessage)
     }
 #endif
     GMX_RELEASE_ASSERT(status == CL_SUCCESS,
-                       gmx::formatString("An unexpected value was returned from clGetPlatformIDs %u: %s",
+                       gmx::formatString("An unexpected value was returned from clGetPlatformIDs %d: %s",
                                          status, ocl_get_error_string(status).c_str()).c_str());
     bool foundPlatform = (numPlatforms > 0);
     if (!foundPlatform && errorMessage != nullptr)
@@ -196,7 +196,7 @@ void findGpus(gmx_gpu_info_t *gpu_info)
         cl_int status = clGetPlatformIDs(0, nullptr, &ocl_platform_count);
         if (CL_SUCCESS != status)
         {
-            GMX_THROW(gmx::InternalError(gmx::formatString("An unexpected value %u was returned from clGetPlatformIDs: ",
+            GMX_THROW(gmx::InternalError(gmx::formatString("An unexpected value %d was returned from clGetPlatformIDs: ",
                                                            status) + ocl_get_error_string(status)));
         }
 
@@ -211,7 +211,7 @@ void findGpus(gmx_gpu_info_t *gpu_info)
         status = clGetPlatformIDs(ocl_platform_count, ocl_platform_ids, nullptr);
         if (CL_SUCCESS != status)
         {
-            GMX_THROW(gmx::InternalError(gmx::formatString("An unexpected value %u was returned from clGetPlatformIDs: ",
+            GMX_THROW(gmx::InternalError(gmx::formatString("An unexpected value %d was returned from clGetPlatformIDs: ",
                                                            status) + ocl_get_error_string(status)));
         }
 
index 9748c8e4a0b7aba59606d52ac112046b84503d19..dc58b6025b8d72c535219fe6c2f3ccded1795f2a 100644 (file)
@@ -302,7 +302,7 @@ static std::string detected_hardware_string(const gmx_hw_info_t *hwinfo,
             s += gmx::formatString("    Numa nodes:\n");
             for (auto &n : hwTop.machine().numa.nodes)
             {
-                s += gmx::formatString("      Node %2d (%" PRIu64 " bytes mem):", n.id, n.memory);
+                s += gmx::formatString("      Node %2d (%zu bytes mem):", n.id, n.memory);
                 for (auto &l : n.logicalProcessorId)
                 {
                     s += gmx::formatString(" %3d", l);
@@ -312,12 +312,12 @@ static std::string detected_hardware_string(const gmx_hw_info_t *hwinfo,
             s += gmx::formatString("      Latency:\n          ");
             for (std::size_t j = 0; j < hwTop.machine().numa.nodes.size(); j++)
             {
-                s += gmx::formatString(" %5lu", j);
+                s += gmx::formatString(" %5zu", j);
             }
             s += gmx::formatString("\n");
             for (std::size_t i = 0; i < hwTop.machine().numa.nodes.size(); i++)
             {
-                s += gmx::formatString("     %5lu", i);
+                s += gmx::formatString("     %5zu", i);
                 for (std::size_t j = 0; j < hwTop.machine().numa.nodes.size(); j++)
                 {
                     s += gmx::formatString(" %5.2f", hwTop.machine().numa.relativeLatency[i][j]);
@@ -329,7 +329,7 @@ static std::string detected_hardware_string(const gmx_hw_info_t *hwinfo,
             s += gmx::formatString("    Caches:\n");
             for (auto &c : hwTop.machine().caches)
             {
-                s += gmx::formatString("      L%d: %" PRIu64 " bytes, linesize %d bytes, assoc. %d, shared %d ways\n",
+                s += gmx::formatString("      L%d: %zu bytes, linesize %d bytes, assoc. %d, shared %d ways\n",
                                        c.level, c.size, c.linesize, c.associativity, c.shared);
             }
         }
index e9d770612746bcd79d90571041be671925d2cc77..af964153709b962094720e5323b7912872c083f2 100644 (file)
@@ -48,6 +48,7 @@
 #include "config.h"
 
 #include <cassert>
+#include <cinttypes>
 #include <climits>
 #include <cstdlib>
 
@@ -450,7 +451,7 @@ void setup_bonded_threading(bonded_threading_t *bt,
             if (gmx_debug_at)
             {
 #if BITMASK_SIZE <= 64 //move into bitmask when it is C++
-                std::string flags = gmx::formatString("%lx", *mask);
+                std::string flags = gmx::formatString("%" PRIx64, *mask);
 #else
                 std::string flags = gmx::formatAndJoin(*mask,
                                                        "", gmx::StringFormatter("%x"));
index e37b56ae7807c68e195919b8b26b75d7e93e0aee..85427ce1627d23f49a170044e706c77dff74bcd3 100644 (file)
@@ -1318,7 +1318,7 @@ static void set_lincs_matrix_task(Lincs                *li,
                             li_task->ntriangle++;
                             if (li->blnr[i+1] - li->blnr[i] > static_cast<int>(sizeof(li_task->tri_bits[0])*8 - 1))
                             {
-                                gmx_fatal(FARGS, "A constraint is connected to %d constraints, this is more than the %lu allowed for constraints participating in triangles",
+                                gmx_fatal(FARGS, "A constraint is connected to %d constraints, this is more than the %zu allowed for constraints participating in triangles",
                                           li->blnr[i+1] - li->blnr[i],
                                           sizeof(li_task->tri_bits[0])*8-1);
                             }
index 3ef88eaea15612c99d205ac6a2b320bbe7b2cb5c..443d6563660d73197349f097784f0fec8b6b49ce 100644 (file)
@@ -139,7 +139,7 @@ static inline void validate_global_work_size(const KernelLaunchConfig &config, i
             {
                 gmx_fatal(FARGS, "Watch out, the input system is too large to simulate!\n"
                           "The number of nonbonded work units (=number of super-clusters) exceeds the"
-                          "device capabilities. Global work size limit exceeded (%d > %d)!",
+                          "device capabilities. Global work size limit exceeded (%zu > %zu)!",
                           global_work_size[i], device_limit);
             }
         }
index eae0873ae6e909b79e13e30b4567827fb7ed9ccf..fbb2ab1bb94dd9925c8fa2e3ad1c3c6a7d550da1 100644 (file)
@@ -1726,7 +1726,7 @@ static void make_fep_list(const nbnxn_search     *nbs,
 
     if (ngid*gridj->na_cj > gmx::index(sizeof(gid_cj)*8))
     {
-        gmx_fatal(FARGS, "The Verlet scheme with %dx%d kernels and free-energy only supports up to %lu energy groups",
+        gmx_fatal(FARGS, "The Verlet scheme with %dx%d kernels and free-energy only supports up to %zu energy groups",
                   gridi->na_c, gridj->na_cj, (sizeof(gid_cj)*8)/gridj->na_cj);
     }
 
index a7926bce9fc0f46db156b89a05a03eea403113f8..b34c2544f2039d015df4f7a3649602cc2711f01e 100644 (file)
@@ -471,7 +471,7 @@ static std::string formatListSetup(const std::string &listName,
     }
     listSetup += "updated every ";
     // Make the shortest int format string that fits nstListForSpacing
-    std::string nstListFormat = "%" + gmx::formatString("%lu", gmx::formatString("%d", nstListForSpacing).size()) + "d";
+    std::string nstListFormat = "%" + gmx::formatString("%zu", gmx::formatString("%d", nstListForSpacing).size()) + "d";
     listSetup += gmx::formatString(nstListFormat.c_str(), nstList);
     listSetup += gmx::formatString(" steps, buffer %.3f nm, rlist %.3f nm\n",
                                    rList - interactionCutoff, rList);
index e0b3fefb67a50f625f41be0f4d97aea82dc9c9c6..51d40ab0125ff9802c2bc042fad4f9278d0bd70c 100644 (file)
@@ -501,7 +501,7 @@ gmx_shellfc_t *init_shell_flexcon(FILE *fplog,
                             case F_ANHARM_POL:
                                 if (!gmx_within_tol(qS, atom[aS].qB, GMX_REAL_EPS*10))
                                 {
-                                    gmx_fatal(FARGS, "polarize can not be used with qA(%e) != qB(%e) for atom %d of molecule block %lu", qS, atom[aS].qB, aS+1, mb+1);
+                                    gmx_fatal(FARGS, "polarize can not be used with qA(%e) != qB(%e) for atom %d of molecule block %zu", qS, atom[aS].qB, aS+1, mb+1);
                                 }
                                 shell[nsi].k    += gmx::square(qS)*ONE_4PI_EPS0/
                                     ffparams->iparams[type].polarize.alpha;
@@ -509,7 +509,7 @@ gmx_shellfc_t *init_shell_flexcon(FILE *fplog,
                             case F_WATER_POL:
                                 if (!gmx_within_tol(qS, atom[aS].qB, GMX_REAL_EPS*10))
                                 {
-                                    gmx_fatal(FARGS, "water_pol can not be used with qA(%e) != qB(%e) for atom %d of molecule block %lu", qS, atom[aS].qB, aS+1, mb+1);
+                                    gmx_fatal(FARGS, "water_pol can not be used with qA(%e) != qB(%e) for atom %d of molecule block %zu", qS, atom[aS].qB, aS+1, mb+1);
                                 }
                                 alpha          = (ffparams->iparams[type].wpol.al_x+
                                                   ffparams->iparams[type].wpol.al_y+
index 05daa4b60a78cb890ede6f9b61d081ce69b53d2a..68d8b0bfc4fbc1048c59c538af118ba32c004af7 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "config.h"
 
+#include <cinttypes>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
@@ -772,11 +773,11 @@ void gmx::Integrator::do_md()
             {
                 if (!rerun_fr.bBox)
                 {
-                    gmx_fatal(FARGS, "Rerun trajectory frame step %ld time %f does not contain a box, while pbc is used", rerun_fr.step, rerun_fr.time);
+                    gmx_fatal(FARGS, "Rerun trajectory frame step %" PRId64 " time %f does not contain a box, while pbc is used", rerun_fr.step, rerun_fr.time);
                 }
                 if (max_cutoff2(ir->ePBC, rerun_fr.box) < gmx::square(fr->rlist))
                 {
-                    gmx_fatal(FARGS, "Rerun trajectory frame step %ld time %f has too small box dimensions", rerun_fr.step, rerun_fr.time);
+                    gmx_fatal(FARGS, "Rerun trajectory frame step %" PRId64 " time %f has too small box dimensions", rerun_fr.step, rerun_fr.time);
                 }
             }
         }
index 725857f909904f935e3439aad600d02372b091df..79af995e5b526263ef8d4660dc57f0275f60a547 100644 (file)
@@ -48,6 +48,7 @@
 #include "config.h"
 
 #include <cassert>
+#include <cinttypes>
 #include <csignal>
 #include <cstdlib>
 #include <cstring>
@@ -303,7 +304,7 @@ static void override_nsteps_cmdline(const gmx::MDLogger &mdlog,
     }
     else if (nsteps_cmdline < -2)
     {
-        gmx_fatal(FARGS, "Invalid nsteps value passed on the command line: %ld",
+        gmx_fatal(FARGS, "Invalid nsteps value passed on the command line: %" PRId64,
                   nsteps_cmdline);
     }
     /* Do nothing if nsteps_cmdline == -2 */
index 792026f3edb1eaec768b98c5415aaeae2250a4aa..8c8fa5527e967e864b97fa6c266b54c0560de232 100644 (file)
@@ -41,6 +41,7 @@
 #include "config.h"
 
 #include <cassert>
+#include <cinttypes>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
@@ -1112,7 +1113,7 @@ static void do_constraint(struct pull_t *pull, t_pbc *pbc,
 
         if (dnorm2(r_ij[c]) == 0)
         {
-            gmx_fatal(FARGS, "Distance for pull coordinate %lu is zero with constraint pulling, which is not allowed.", c + 1);
+            gmx_fatal(FARGS, "Distance for pull coordinate %zu is zero with constraint pulling, which is not allowed.", c + 1);
         }
     }
 
index 6ac6d36ad1e7fefe64a0215d4427c464f258c3f7..bf9b2ee572d843db3311003ab78e08d57dadfffa 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/stringutil.h"
 
 #include "selmethod-impl.h"
 #include "symrec.h"
@@ -72,7 +73,10 @@ typedef struct {
  * Convenience function for reporting errors found in selection methods.
  */
 static void
-report_error(FILE *fp, const char *name, const char *fmt, ...)
+report_error(FILE *fp, const char *name, gmx_fmtstr const char *fmt, ...) gmx_format(printf, 3, 4);
+
+static void
+report_error(FILE *fp, const char *name, gmx_fmtstr const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
@@ -90,7 +94,10 @@ report_error(FILE *fp, const char *name, const char *fmt, ...)
  */
 static void
 report_param_error(FILE *fp, const char *mname, const char *pname,
-                   const char *fmt, ...)
+                   gmx_fmtstr const char *fmt, ...) gmx_format(printf, 4, 5);
+static void
+report_param_error(FILE *fp, const char *mname, const char *pname,
+                   gmx_fmtstr const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
index fc1f4941b715f7185a3d166a16695953b32782b9..9a21fe2e03599c61c6f14e35334d72229f63b2ac 100644 (file)
@@ -143,7 +143,7 @@ throwUnlessDerivativeIsConsistentWithFunction(ArrayRef<const double>        func
     }
     if (!isConsistent)
     {
-        GMX_THROW(InconsistentInputError(formatString("Derivative inconsistent with numerical vector for elements %lu-%lu", minFail+1, maxFail+1)));
+        GMX_THROW(InconsistentInputError(formatString("Derivative inconsistent with numerical vector for elements %zu-%zu", minFail+1, maxFail+1)));
     }
 }
 
index c3dfac65f86ea22c24085ac475a4ae60b713724f..bfb27986b821845294971f2c2c104735611eeaa0 100644 (file)
@@ -226,7 +226,7 @@ void gmx_fatal_mpi_va(int /*f_errno*/, const char *file, int line,
     gmx_exit_on_fatal_error(exitType, 1);
 }
 
-void gmx_fatal(int f_errno, const char *file, int line, const char *fmt, ...)
+void gmx_fatal(int f_errno, const char *file, int line, gmx_fmtstr const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
@@ -264,7 +264,7 @@ void _range_check(int n, int n_min, int n_max, const char *warn_str,
     }
 }
 
-void gmx_warning(const char *fmt, ...)
+void gmx_warning(gmx_fmtstr const char *fmt, ...)
 {
     va_list ap;
     char    msg[STRLEN];
index 329de245ddaf2dbace9d43db5d4ff57bdffbfce3..0f5ce2b50731e50e18143a91a4521d3dee55d8ad 100644 (file)
@@ -48,6 +48,7 @@
 #include <stdio.h>
 
 #include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/stringutil.h"
 
 /*! \brief
  * Debug log file.
@@ -173,7 +174,7 @@ gmx_fatal_mpi_va(int fatal_errno, const char *file, int line,
    \endcode
  */
 [[noreturn]] void
-gmx_fatal(int fatal_errno, const char *file, int line, const char *fmt, ...);
+gmx_fatal(int fatal_errno, const char *file, int line, gmx_fmtstr const char *fmt, ...) gmx_format(printf, 4, 5);
 /** Helper macro to pass first three parameters to gmx_fatal(). */
 #define FARGS 0, __FILE__, __LINE__
 
@@ -235,6 +236,6 @@ void _range_check(int n, int n_min, int n_max, const char *warn_str,
  * The message string should NOT start with "WARNING"
  * and should NOT end with a newline.
  */
-void gmx_warning(const char *fmt, ...);
+void gmx_warning(gmx_fmtstr const char *fmt, ...) gmx_format(printf, 1, 2);
 
 #endif
index 7be58088b45acc62a9f1626c830a2d3442f180c2..e334634a7e93369c19fcd6f957c2e55bce36cb5c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -60,7 +60,7 @@ ILogTarget::~ILogTarget()
 }
 
 
-LogEntryWriter &LogEntryWriter::appendTextFormatted(const char *fmt, ...)
+LogEntryWriter &LogEntryWriter::appendTextFormatted(gmx_fmtstr const char *fmt, ...)
 {
     va_list ap;
 
index f04af827fa47440e5e0f320ba5df7a4963b5b5fe..dc09a8d3fa32f8bcb5c3fa486792bf5919fabf00 100644 (file)
@@ -46,6 +46,8 @@
 
 #include <string>
 
+#include "gromacs/utility/stringutil.h"
+
 namespace gmx
 {
 
@@ -92,7 +94,7 @@ class LogEntryWriter
             return *this;
         }
         //! Appends given text as a line in the log entry, with printf-style formatting.
-        LogEntryWriter &appendTextFormatted(const char *fmt, ...);
+        LogEntryWriter &appendTextFormatted(gmx_fmtstr const char *fmt, ...) gmx_format(printf, 2, 3);
         //! Writes the log entry with empty lines before and after.
         LogEntryWriter &asParagraph()
         {
index ad0f963bf39cd9f966a309770583e68f5014914b..f42a3f16d9c709c254fa83e146d91bcfd2e795b9 100644 (file)
@@ -133,7 +133,7 @@ std::string stripString(const std::string &str)
     return std::string(start, end);
 }
 
-std::string formatString(const char *fmt, ...)
+std::string formatString(gmx_fmtstr const char *fmt, ...)
 {
     va_list     ap;
     va_start(ap, fmt);
index 2c0be63baa9c37d52b6a027d2fbbde9be65d0fa6..b3cca7e3e3c899575cb74d290048672e874823c2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -168,6 +168,31 @@ std::string stripSuffixIfPresent(const std::string &str, const char *suffix);
  * \throws    std::bad_alloc if out of memory.
  */
 std::string stripString(const std::string &str);
+#ifdef __GNUC__
+#define gmx_format(archetype, string_index, first_to_check) \
+    __attribute__ ((format (archetype, string_index, first_to_check)))
+#else
+/*! \brief GCC like function format attribute
+ *
+ * The format attribute specifies that a function takes printf, scanf, ...
+ * style arguments that should be type-checked against a format string.
+ * The attribute has to be placed after the function.
+ * This attribute is only valid for function declarations and not function
+ * definitions (GCC limitation). For member functions the implicit `this`
+ * pointer is included in the argument count.
+ */
+#define gmx_format(archetype, string_index, first_to_check)
+#endif
+#ifdef _MSC_VER
+#define gmx_fmtstr _In_ _Printf_format_string_
+#else
+/*! \brief MSVC like function format attribute
+ *
+ * Does type checking for printf like format strings in MSVC style.
+ * Attribute has to be placed before format string.
+ */
+#define gmx_fmtstr
+#endif
 /*! \brief
  * Formats a string (snprintf() wrapper).
  *
@@ -177,7 +202,8 @@ std::string stripString(const std::string &str);
  * instead of requiring a preallocated buffer.  Arbitrary length output is
  * supported.
  */
-std::string formatString(const char *fmt, ...);
+std::string formatString(gmx_fmtstr const char *fmt, ...) gmx_format(printf, 1, 2);
+
 /*! \brief
  * Formats a string (vsnprintf() wrapper).
  *