]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
silence signed overflow warning
authorDave Hart <hart@ntp.org>
Wed, 26 Jan 2011 19:39:27 +0000 (19:39 +0000)
committerDave Hart <hart@ntp.org>
Wed, 26 Jan 2011 19:39:27 +0000 (19:39 +0000)
mark isc_assertioncallback_t __attribute((__noreturn__))

bk: 4d40786fLaPLnWCfVNX5QCVOtpIMAQ

include/ntp_stdlib.h
lib/isc/assertions.c
lib/isc/include/isc/assertions.h
libntp/timetoa.c
ntpd/ntpd.c

index b147be06a6d7afb348bff87aba9152e70d1b2460..e5e4ab4baa3fefda19742375fdda4ba29391df59 100644 (file)
 
 
 /*
- * Handle gcc __attribute__ if available.
+ * #define away gcc __attribute__ if unavailable.
  */
 #ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
+  /* This feature is available in gcc versions 2.5 and later.  */
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (defined(__STRICT_ANSI__))
 #  define __attribute__(Spec) /* empty */
 # endif
-/* The __-protected variants of `format' and `printf' attributes
-   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+  /*
+   * The __-protected variants of `format' and `printf' attributes are
+   * accepted by gcc versions 2.6.4 (effectively 2.7) and later.
+   */
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-#  define __format__ format
-#  define __printf__ printf
+#  define __format__   format
+#  define __printf__   printf
+#  define __noreturn__ noreturn
 # endif
 #endif
 
index 4c9251bdcf25199dd622049ae35821775caf842d..8db4cdef89808f2e151e3061b32e4107150136a1 100644 (file)
@@ -32,7 +32,8 @@
  */
 /* coverity[+kill] */
 static void
-default_callback(const char *, int, isc_assertiontype_t, const char *);
+default_callback(const char *, int, isc_assertiontype_t, const char *)
+       __attribute__ ((__noreturn__));
 
 /*%
  * Public.
index b03115216909b8f9d8bcfed5b3327173ad91fa22..adc083f320e4f97ac785a6541df15bca277d6c4b 100644 (file)
 #include <isc/lang.h>
 #include <isc/platform.h>
 
+/*
+ * #define away gcc __attribute__ if unavailable.
+ */
+#ifndef __attribute__
+  /* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (defined(__STRICT_ANSI__))
+#  define __attribute__(Spec) /* empty */
+# endif
+  /*
+   * The __-protected variants of `format' and `printf' attributes are
+   * accepted by gcc versions 2.6.4 (effectively 2.7) and later.
+   */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__   format
+#  define __printf__   printf
+#  define __noreturn__ noreturn
+# endif
+#endif
+
 ISC_LANG_BEGINDECLS
 
 /*% isc assertion type */
@@ -38,7 +57,8 @@ typedef enum {
 } isc_assertiontype_t;
 
 typedef void (*isc_assertioncallback_t)(const char *, int, isc_assertiontype_t,
-                                       const char *);
+                                       const char *)
+                                       __attribute__ ((__noreturn__));
 
 /* coverity[+kill] */
 LIBISC_EXTERNAL_DATA extern isc_assertioncallback_t isc_assertion_failed;
index 2f0a7daa387b0ed658abe89d6123df1a77f04866..c04d34ea06397055b14eb3dfe4d8083168f9859c 100644 (file)
@@ -52,8 +52,9 @@ format_time_fraction(
        )
 {
        char *          cp;
-       u_time          ttmp;   /* unsigned storage for seconds */
-       int             i;
+       u_int           prec_u;
+       u_time          secs_u;
+       u_int           u;
        long            fraclimit;
        int             notneg; /* flag for non-negative value  */
        const char *    fmt;
@@ -62,16 +63,17 @@ format_time_fraction(
        DEBUG_REQUIRE(prec != 0);
 
        LIB_GETBUF(cp);
-       ttmp = (u_time)secs;
+       secs_u = (u_time)secs;
        fmt = "-%" UTIME_FORMAT ".%0*ld";
        
        /* check if we need signed or unsigned mode */
        notneg = (prec < 0);
-       prec = abs(prec);
-       /* fraclimit = (long)pow(10, prec); */
-       for (fraclimit = 10, i = 1; i < prec; i++)
+       prec_u = abs(prec);
+       /* fraclimit = (long)pow(10, prec_u); */
+       for (fraclimit = 10, u = 1; u < prec_u; u++) {
+               DEBUG_INSIST(fraclimit < fraclimit * 10);
                fraclimit *= 10;
-       DEBUG_INSIST(fraclimit > 0);
+       }
 
        /*
         * Since conversion to string uses lots of divisions anyway,
@@ -84,24 +86,24 @@ format_time_fraction(
                        qr.quot--;
                        qr.rem += fraclimit;
                }
-               ttmp += (time_t)qr.quot;
+               secs_u += (time_t)qr.quot;
                frac = qr.rem;
        }
 
-       /* Get the absolute value of the time stamp. */
-       notneg = notneg || ((time_t)ttmp >= 0);
+       /* Get the absolute value of the split representation time. */
+       notneg = notneg || ((time_t)secs_u >= 0);
        if (notneg) {
-               fmt++; /* skip sign char in format string */
+               fmt++;          /* skip '-' */
        } else {
-               ttmp = ~ttmp;
-               if (frac != 0)
-                       frac = fraclimit - frac;
+               secs_u = ~secs_u;
+               if (0 == frac)
+                       secs_u++;
                else
-                       ttmp += 1;
+                       frac = fraclimit - frac;
        }
 
        /* finally format the data and return the result */
-       snprintf(cp, LIB_BUFLENGTH, fmt, ttmp, prec, frac);
+       snprintf(cp, LIB_BUFLENGTH, fmt, secs_u, prec_u, frac);
        
        return cp;
 }
index 3ab9675ec9178f5d1214de50e95aeb1ed27d0446..24c1816580ff523a198a04df461e71f34199121c 100644 (file)
@@ -236,7 +236,8 @@ int         ntpdmain                (int, char **);
 static void    set_process_priority    (void);
 static void    assertion_failed        (const char *, int,
                                         isc_assertiontype_t,
-                                        const char *);
+                                        const char *)
+                       __attribute__   ((__noreturn__));
 static void    library_fatal_error     (const char *, int, 
                                         const char *, va_list)
                                        ISC_FORMAT_PRINTF(3, 0);