amkozlov / raxml-ng

RAxML Next Generation: faster, easier-to-use and more flexible
GNU Affero General Public License v3.0
374 stars 62 forks source link

Wrong format specifier for size_t variables #145

Closed jdx-gh closed 1 year ago

jdx-gh commented 1 year ago

The proper format specifier for size_t variables is %z. See https://stackoverflow.com/questions/2125845/platform-independent-size-t-format-specifiers-in-c.

Here is the patch:

diff --git a/src/PartitionInfo.cpp b/src/PartitionInfo.cpp
index 47affb3..baef291 100644
--- a/src/PartitionInfo.cpp
+++ b/src/PartitionInfo.cpp
@@ -34,18 +34,18 @@ size_t PartitionInfo::mark_partition_sites(unsigned int part_num, std::vector<un

     int read = 0;
     /* try to parse strided format first */
-    read = sscanf(range, "%lu-%lu\\%lu", &start, &end, &stride);
+    read = sscanf(range, "%zu-%zu\\%zu", &start, &end, &stride);
     if (read != 3)
-      read = sscanf(range, "%lu-%lu/%lu", &start, &end, &stride);
+      read = sscanf(range, "%zu-%zu/%zu", &start, &end, &stride);
     if (read != 3)
     {
       /* try to parse contiguous range format first */
       stride = 1;
-      read = sscanf(range, "%lu-%lu", &start, &end);
+      read = sscanf(range, "%zu-%zu", &start, &end);
       if (read != 2)
       {
         /* finally, check if we have a single column */
-        read = sscanf(range, "%lu", &start);
+        read = sscanf(range, "%zu", &start);
         end = start;
       }
     }
amkozlov commented 1 year ago

merged into dev, thank you!