From: Dave Hart Date: Wed, 26 Jan 2011 19:39:27 +0000 (+0000) Subject: silence signed overflow warning X-Git-Tag: NTP_4_2_7P126~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a0183c003ca3539a09ff489882ae5271a0f7ab5;p=thirdparty%2Fntp.git silence signed overflow warning mark isc_assertioncallback_t __attribute((__noreturn__)) bk: 4d40786fLaPLnWCfVNX5QCVOtpIMAQ --- diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index b147be06a..e5e4ab4ba 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -17,18 +17,21 @@ /* - * 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 diff --git a/lib/isc/assertions.c b/lib/isc/assertions.c index 4c9251bdc..8db4cdef8 100644 --- a/lib/isc/assertions.c +++ b/lib/isc/assertions.c @@ -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. diff --git a/lib/isc/include/isc/assertions.h b/lib/isc/include/isc/assertions.h index b03115216..adc083f32 100644 --- a/lib/isc/include/isc/assertions.h +++ b/lib/isc/include/isc/assertions.h @@ -27,6 +27,25 @@ #include #include +/* + * #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; diff --git a/libntp/timetoa.c b/libntp/timetoa.c index 2f0a7daa3..c04d34ea0 100644 --- a/libntp/timetoa.c +++ b/libntp/timetoa.c @@ -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; } diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 3ab9675ec..24c181658 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -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);