[Git][NTPsec/ntpsec][master] 3 commits: fix some sign conversion warnings
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Mar 12 20:17:07 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
699779bf by Achim Gratz at 2017-03-12T16:16:31-04:00
fix some sign conversion warnings
include/ntp_fp.h (bumplfpsint): use modulo arithmetic throughout.
(L_NEG): explicitly cast back to l_fp after doing signed arithmetic.
libparse/clk_trimtsip.c (cvt_trimtsip): Calculation needs unsigned
operands for modulo arithmetic, explicit cast to time_t needed.
- - - - -
3e986146 by Achim Gratz at 2017-03-12T16:16:38-04:00
Make constants for parse flags unsigned.
- - - - -
68e18ba6 by Achim Gratz at 2017-03-12T16:16:52-04:00
Make ext_bf return long, fix signedness of l_fp manipulations
libparse/clk_rawdcf.c (ext_bf): Return long to match type of target.
calc_usecdiff): Request signed value.
- - - - -
5 changed files:
- include/ntp_fp.h
- include/parse.h
- include/timespecops.h
- libparse/clk_rawdcf.c
- libparse/clk_trimtsip.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -61,7 +61,7 @@ typedef uint64_t l_fp;
#define lfptouint(n) ((uint64_t)((uint64_t)(n) << 32))
#define lfpsint(n) (( int32_t)((n) >> 32))
#define lfpuint(n) ((uint32_t)((n) >> 32))
-#define bumplfpsint(n, i) ((n) += lfptosint(i))
+#define bumplfpsint(n, i) ((n) += lfptouint(i))
#define bumplfpuint(n, i) ((n) += lfptouint(i))
#define setlfpfrac(n, v) ((n) = (lfptouint(lfpuint(n)) | lfpfrac(v)))
#define setlfpsint(n, v) ((n) = (lfptosint(v) | lfpfrac(n)))
@@ -142,7 +142,7 @@ static inline l_fp ntohl_fp(l_fp_w lfpw) {
* native operations is to be independent of whether the l_fp
* type is signed or unsigned.
*/
-#define L_NEG(v) (v) = (-1 * (int64_t)(v))
+#define L_NEG(v) (v) = (l_fp)(-1 * (int64_t)(v))
#define L_ISNEG(v) M_ISNEG(lfpuint(v))
#define L_ISGT(a, b) ((int64_t)(a) > (int64_t)(b))
#define L_ISGTU(a, b) ((a) > (b))
=====================================
include/parse.h
=====================================
--- a/include/parse.h
+++ b/include/parse.h
@@ -30,42 +30,42 @@
/*
* state flags
*/
-#define PARSEB_POWERUP 0x00000001 /* no synchronisation */
-#define PARSEB_NOSYNC 0x00000002 /* timecode currently not confirmed */
+#define PARSEB_POWERUP 0x00000001U /* no synchronisation */
+#define PARSEB_NOSYNC 0x00000002U /* timecode currently not confirmed */
/*
* time zone information
*/
-#define PARSEB_ANNOUNCE 0x00000010 /* switch time zone warning (DST switch) */
-#define PARSEB_DST 0x00000020 /* DST in effect */
-#define PARSEB_UTC 0x00000040 /* UTC time */
+#define PARSEB_ANNOUNCE 0x00000010U /* switch time zone warning (DST switch) */
+#define PARSEB_DST 0x00000020U /* DST in effect */
+#define PARSEB_UTC 0x00000040U /* UTC time */
/*
* leap information
*/
-#define PARSEB_LEAPDEL 0x00000100 /* LEAP deletion warning */
-#define PARSEB_LEAPADD 0x00000200 /* LEAP addition warning */
-#define PARSEB_LEAPS 0x00000300 /* LEAP warnings */
-#define PARSEB_LEAPSECOND 0x00000400 /* actual leap second */
+#define PARSEB_LEAPDEL 0x00000100U /* LEAP deletion warning */
+#define PARSEB_LEAPADD 0x00000200U /* LEAP addition warning */
+#define PARSEB_LEAPS 0x00000300U /* LEAP warnings */
+#define PARSEB_LEAPSECOND 0x00000400U /* actual leap second */
/*
* optional status information
*/
-#define PARSEB_CALLBIT 0x00001000 /* "call bit" used to signalize irregularities in the control facilities */
-#define PARSEB_POSITION 0x00002000 /* position available */
-#define PARSEB_MESSAGE 0x00004000 /* addtitional message data */
+#define PARSEB_CALLBIT 0x00001000U /* "call bit" used to signalize irregularities in the control facilities */
+#define PARSEB_POSITION 0x00002000U /* position available */
+#define PARSEB_MESSAGE 0x00004000U /* addtitional message data */
/*
* feature information
*/
-#define PARSEB_S_LEAP 0x00010000 /* supports LEAP */
-#define PARSEB_S_CALLBIT 0x00020000 /* supports callbit information */
-#define PARSEB_S_PPS 0x00040000 /* supports PPS time stamping */
-#define PARSEB_S_POSITION 0x00080000 /* supports position information (GPS) */
+#define PARSEB_S_LEAP 0x00010000U /* supports LEAP */
+#define PARSEB_S_CALLBIT 0x00020000U /* supports callbit information */
+#define PARSEB_S_PPS 0x00040000U /* supports PPS time stamping */
+#define PARSEB_S_POSITION 0x00080000U /* supports position information (GPS) */
/*
* time stamp availability
*/
-#define PARSEB_TIMECODE 0x10000000 /* valid time code sample */
-#define PARSEB_PPS 0x20000000 /* valid PPS sample */
+#define PARSEB_TIMECODE 0x10000000U /* valid time code sample */
+#define PARSEB_PPS 0x20000000U /* valid PPS sample */
#define PARSE_TCINFO (PARSEB_ANNOUNCE|PARSEB_POWERUP|PARSEB_NOSYNC|PARSEB_DST|\
PARSEB_UTC|PARSEB_LEAPS|PARSEB_CALLBIT|PARSEB_S_LEAP|\
@@ -208,7 +208,7 @@ struct clocktime /* clock time broken up from time code */
long usecond;
long utcoffset; /* in seconds */
time_t utctime; /* the actual time - alternative to date/time */
- unsigned long flags; /* current clock status */
+ unsigned long flags; /* current clock status */
};
typedef struct clocktime clocktime_t;
=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -371,7 +371,7 @@ lfp_uintv_to_tspec(
struct timespec out;
out.tv_nsec = FTOTVN(lfpfrac(x));
- out.tv_sec = lfpuint(x);
+ out.tv_sec = lfpsint(x);
return out;
}
=====================================
libparse/clk_rawdcf.c
=====================================
--- a/libparse/clk_rawdcf.c
+++ b/libparse/clk_rawdcf.c
@@ -142,14 +142,14 @@ static struct partab
#define DCF_Z_MET 0x2
#define DCF_Z_MED 0x1
-static unsigned long
+static long
ext_bf(
unsigned char *buf,
int idx,
const unsigned char *zero
)
{
- unsigned long sum = 0;
+ long sum = 0;
int i, first;
first = rawdcfcode[idx].offset;
@@ -509,11 +509,11 @@ calc_usecdiff(
l_fp delt;
delt = *ref;
- bumplfpsint(delt, -offset);
+ bumplfpsint(delt, -offset);
delt -= *base;
- delta = lfp_uintv_to_tspec(delt);
+ delta = lfp_uintv_to_tspec(delt);
- delta_usec = (NANOSECONDS/1000)*(int32_t)delta.tv_sec + delta.tv_nsec/1000;
+ delta_usec = MICROSECONDS*(int32_t)delta.tv_sec + delta.tv_nsec/1000;
return delta_usec;
}
=====================================
libparse/clk_trimtsip.c
=====================================
--- a/libparse/clk_trimtsip.c
+++ b/libparse/clk_trimtsip.c
@@ -248,7 +248,7 @@ cvt_trimtsip(
setlfpfrac(gpstime, lfpfrac(secs));
- clock_time->utctime = lfpuint(gpstime) - JAN_1970;
+ clock_time->utctime = (time_t)(lfpuint(gpstime) - JAN_1970);
clock_time->usecond = lfp_intv_to_tspec(gpstime).tv_nsec / 1000;
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a58fe23d91eee1478f08a4e08d8d75a37ace6f8f...68e18ba692d3cbc70654963f1d4efb597ead654a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170312/8997974a/attachment.html>
More information about the vc
mailing list