]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Change new timeval and timespec to string routines to use snprintf()
authorDave Hart <hart@ntp.org>
Thu, 20 Jan 2011 08:27:32 +0000 (08:27 +0000)
committerDave Hart <hart@ntp.org>
Thu, 20 Jan 2011 08:27:32 +0000 (08:27 +0000)
  rather than hand-crafted conversion, avoid signed int overflow there.
Add configure support for SIZEOF_LONG_LONG to enable portable use of
  snprintf() with time_t.

bk: 4d37f1f4gpu7tDOPSbW-bC83_nxKtg

ChangeLog
configure.ac
libntp/timespecops.c
libntp/timevalops.c
ports/winnt/include/config.h
sntp/configure.ac
sntp/m4/ntp_libntp.m4

index 6492559022c188d68684cdbd26ea4642a4779dfd..aed39f67e3fbd06fcb366d99f5ecf9bb8c0d47ef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
-* changed timeval / timespec string conversion (snprintf() format
-  strings for time_t vs. int / long / long long; avoid signed integer
-  overflow)
+* Change new timeval and timespec to string routines to use snprintf()
+  rather than hand-crafted conversion, avoid signed int overflow there.
+* Add configure support for SIZEOF_LONG_LONG to enable portable use of
+  snprintf() with time_t.
 * Grow ntpd/work_thread.c arrays as needed.
 * Add DEBUG_* variants of ntp_assert.h macros which compile away using
   ./configure --disable-debugging.
index e3015c83ef8eac3212d281e414ab47e9ed816f6e..a447bde39b01ee0e3164b89433f15dcc38e4f711 100644 (file)
@@ -415,7 +415,6 @@ AC_EGREP_CPP(
     )]
 )
 AC_CHECK_HEADERS([sys/timers.h sys/tpro.h sys/types.h sys/wait.h])
-AC_HEADER_TIME
 case "$host" in
 *-convex-*)
     AC_CHECK_HEADERS([/sys/sync/queue.h /sys/sync/sema.h])
@@ -933,49 +932,6 @@ AC_CHECK_MEMBERS(
     ]
 )
 
-AC_C_INLINE
-
-case "$ac_cv_c_inline" in
- '')
-    ;;
- *)
-    AC_DEFINE([HAVE_INLINE], [1], [inline keyword or macro available])
-    AC_SUBST([HAVE_INLINE])
-esac
-
-AC_C_CHAR_UNSIGNED             dnl CROSS_COMPILE?
-AC_CHECK_SIZEOF([signed char])
-AC_CHECK_TYPES([s_char])
-AC_CHECK_SIZEOF([short])
-AC_CHECK_SIZEOF([int])
-AC_CHECK_SIZEOF([long])
-
-case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
- *yes)
-    # We have a typedef for s_char.  Might as well believe it...
-    ;;
- no0no)
-    # We have signed chars, can't say 'signed char', no s_char typedef.
-    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
-       [Do we need an s_char typedef?])
-    ;;
- no1no)
-    # We have signed chars, can say 'signed char', no s_char typedef.
-    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
-       [Do we need an s_char typedef?])
-    ;;
- yes0no)
-    # We have unsigned chars, can't say 'signed char', no s_char typedef.
-    AC_MSG_ERROR([No way to specify a signed character!])
-    ;;
- yes1no)
-    # We have unsigned chars, can say 'signed char', no s_char typedef.
-    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
-       [Do we need an s_char typedef?])
-    ;;
-esac
-AC_TYPE_UID_T
-
 case "$host" in
  *-*-aix[[456]]*)
        # (prr) aix 4.1 doesn't have clock_settime, but in aix 4.3 it's a stub
index 849fd3964384775502fdde0579e32509e5445f81..0fd53d37cade20fe6d0c56dd33e5582a68cda000 100644 (file)
@@ -47,11 +47,11 @@ typedef unsigned int u_time;
 #elif SIZEOF_TIME_T <= SIZEOF_LONG
 typedef unsigned long u_time;
 #define TIMEFMT "l"
-#elif SIZEOF_TIME_T <= SIZEOF_LONG_LONG
+#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG
 typedef unsigned long long u_time;
 #define TIMEFMT "ll"
 #else
-# include "GRONK: what size has a time_t here?"
+#include "GRONK: what size has a time_t here?"
 #endif
 
 
index 4699a9c16e135b89e6d89361f1532a8be6cd2d93..623c2f9782be83332d44a0003f9e5b880bf82a51 100644 (file)
@@ -45,11 +45,11 @@ typedef unsigned int u_time;
 #elif SIZEOF_TIME_T <= SIZEOF_LONG
 typedef unsigned long u_time;
 #define TIMEFMT "l"
-#elif SIZEOF_TIME_T <= SIZEOF_LONG_LONG
+#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG
 typedef unsigned long long u_time;
 #define TIMEFMT "ll"
 #else
-# include "GRONK: what size has a time_t here?"
+#include "GRONK: what size has a time_t here?"
 #endif
 
 /* copy and normalise. Used often enough to warrant a macro. */
index 8491b01a4b8e8b4201680454be9a0dc8ae170f92..3f087cc965751d4f91ad20cb4182eb856ac30c3f 100644 (file)
@@ -361,7 +361,9 @@ typedef __int32 int32_t;    /* define a typedef for int32_t */
 
 # define SIZEOF_SIGNED_CHAR    1
 # define SIZEOF_SHORT          2
-# define SIZEOF_INT            4       /* for ntp_types.h */
+# define SIZEOF_INT            4
+# define SIZEOF_LONG           4
+# define SIZEOF_LONG_LONG      8
 
 # define HAVE_ALLOCA
 # define HAVE_SETVBUF
index 875d504d0e3fea237ea231a076af98c3e0a736c9..7984857d4b75b3292edd6e43174236d5703410da 100644 (file)
@@ -101,53 +101,11 @@ AC_HEADER_STDC
 
 AC_CHECK_HEADERS([netdb.h netinet/in.h stdlib.h string.h strings.h syslog.h])
 AC_CHECK_HEADERS([sys/time.h])
-AC_HEADER_TIME
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_HEADER_STDBOOL
 AC_C_CONST
 AC_TYPE_SIZE_T
-AC_CHECK_SIZEOF([time_t])
-
-AC_C_INLINE
-
-case "$ac_cv_c_inline" in
- '')
-    ;;
- *)
-    AC_DEFINE(HAVE_INLINE,1,[inline keyword or macro available])
-    AC_SUBST(HAVE_INLINE)
-esac
-
-AC_C_CHAR_UNSIGNED             dnl CROSS_COMPILE?
-AC_CHECK_SIZEOF([signed char])
-AC_CHECK_SIZEOF([short])
-AC_CHECK_SIZEOF([int])
-AC_CHECK_SIZEOF([long])
-
-AC_CHECK_TYPES([s_char])
-case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
- *yes)
-    # We have a typedef for s_char.  Might as well believe it...
-    ;;
- no0no)
-    # We have signed chars, can't say 'signed char', no s_char typedef.
-    AC_DEFINE([NEED_S_CHAR_TYPEDEF], 1, [Do we need an s_char typedef?])
-    ;;
- no1no)
-    # We have signed chars, can say 'signed char', no s_char typedef.
-    AC_DEFINE([NEED_S_CHAR_TYPEDEF])
-    ;;
- yes0no)
-    # We have unsigned chars, can't say 'signed char', no s_char typedef.
-    AC_MSG_ERROR([No way to specify a signed character!])
-    ;;
- yes1no)
-    # We have unsigned chars, can say 'signed char', no s_char typedef.
-    AC_DEFINE([NEED_S_CHAR_TYPEDEF])
-    ;;
-esac
-AC_TYPE_UID_T
 
 NTP_OPENSSL
 NTP_IPV6
index 04474759782fd938075b0aada7cd6b8dee83027f..c381f3a1cffe99f2a6389aa4cec4cbc816f56e82 100644 (file)
@@ -252,6 +252,59 @@ case "$ac_cv_search_setsockopt" in
 esac
 AS_UNSET([saved_LIBS])
 
+AC_C_INLINE
+
+case "$ac_cv_c_inline" in
+ '')
+    ;;
+ *)
+    AC_DEFINE([HAVE_INLINE], [1], [inline keyword or macro available])
+    AC_SUBST([HAVE_INLINE])
+esac
+
+AC_HEADER_TIME
+AC_CHECK_SIZEOF([time_t])
+AC_C_CHAR_UNSIGNED             dnl CROSS_COMPILE?
+AC_CHECK_SIZEOF([signed char])
+AC_CHECK_TYPES([s_char, long long])
+AC_CHECK_SIZEOF([short])
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([long])
+
+case "$ac_cv_type_long_long" in
+ no)
+    ;;
+ *)
+    AC_CHECK_SIZEOF([long long])
+    ;;
+esac
+
+case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
+ *yes)
+    # We have a typedef for s_char.  Might as well believe it...
+    ;;
+ no0no)
+    # We have signed chars, can't say 'signed char', no s_char typedef.
+    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
+       [Do we need an s_char typedef?])
+    ;;
+ no1no)
+    # We have signed chars, can say 'signed char', no s_char typedef.
+    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
+       [Do we need an s_char typedef?])
+    ;;
+ yes0no)
+    # We have unsigned chars, can't say 'signed char', no s_char typedef.
+    AC_MSG_ERROR([No way to specify a signed character!])
+    ;;
+ yes1no)
+    # We have unsigned chars, can say 'signed char', no s_char typedef.
+    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
+       [Do we need an s_char typedef?])
+    ;;
+esac
+
+AC_TYPE_UID_T
 AC_FUNC_STRERROR_R
 
 dnl preset withsntp=no in env to change default to --without-sntp