swri-robotics / gps_umd

BSD 3-Clause "New" or "Revised" License
88 stars 94 forks source link

Fix truncation warning for UTM zone snprintf() #44

Closed kmhallen closed 2 years ago

kmhallen commented 3 years ago
In file included from /home/kmhallen/ros1/ds/src/gps_umd/gps_common/src/utm_odometry_node.cpp:10:
/home/kmhallen/ros1/ds/src/gps_umd/gps_common/include/gps_common/conversions.h: In function ‘void callback(const NavSatFixConstPtr&)’:
/home/kmhallen/ros1/ds/src/gps_umd/gps_common/include/gps_common/conversions.h:188:24: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 4 [-Wformat-truncation=]
  188 |  snprintf(UTMZone, 4, "%d%c", ZoneNumber, UTMLetterDesignator(Lat));
      |                        ^~
/home/kmhallen/ros1/ds/src/gps_umd/gps_common/include/gps_common/conversions.h:188:23: note: directive argument in the range [-2147483647, 2147483647]
  188 |  snprintf(UTMZone, 4, "%d%c", ZoneNumber, UTMLetterDesignator(Lat));
      |                       ^~~~~~
In file included from /usr/include/stdio.h:867,
                 from /usr/include/c++/9/cstdio:42,
                 from /usr/include/c++/9/ext/string_conversions.h:43,
                 from /usr/include/c++/9/bits/basic_string.h:6493,
                 from /usr/include/c++/9/string:55,
                 from /opt/ros/noetic/include/ros/platform.h:38,
                 from /opt/ros/noetic/include/ros/time.h:53,
                 from /opt/ros/noetic/include/ros/ros.h:38,
                 from /home/kmhallen/ros1/ds/src/gps_umd/gps_common/src/utm_odometry_node.cpp:5:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: ‘__builtin___snprintf_chk’ output between 3 and 13 bytes into a destination of size 4
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~