[Git][NTPsec/ntpsec][master] 17 commits: Make unsigned constants be unsigned.
Gary E. Miller
gitlab at mg.gitlab.com
Sat Apr 1 03:25:43 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
d7b34f9f by Gary E. Miller at 2017-03-31T18:41:32-07:00
Make unsigned constants be unsigned.
- - - - -
9e725f3f by Gary E. Miller at 2017-03-31T18:50:23-07:00
No point casting with (int64_t) to a uint64_t
- - - - -
6762cc0e by Gary E. Miller at 2017-03-31T18:59:05-07:00
htonl() returns an unsigned int, not an int.
- - - - -
539b49cf by Gary E. Miller at 2017-03-31T19:03:48-07:00
Missing int casts, no functional change.
- - - - -
81112f3d by Gary E. Miller at 2017-03-31T19:05:55-07:00
lfpinit() needs an int, not a uint.
No functional change.
- - - - -
68b9f99e by Gary E. Miller at 2017-03-31T19:19:38-07:00
Fixed signed/unsigned mismatch.
No functional change.
- - - - -
b9ba461e by Gary E. Miller at 2017-03-31T19:30:30-07:00
lfpinint() takes an int and a uint32.
No functional change.
- - - - -
1950d6f8 by Gary E. Miller at 2017-03-31T19:36:59-07:00
Add missing cast, no fuction change.
- - - - -
ec7c0a6a by Gary E. Miller at 2017-03-31T19:39:44-07:00
Add two casts, no functioanl change.
- - - - -
6d91bd01 by Gary E. Miller at 2017-03-31T19:48:55-07:00
Get units right for lfpinit().
All tests now pass -Wsign-conversion
Only 317 sign conversion warnings left.
- - - - -
6791d614 by Gary E. Miller at 2017-03-31T19:54:34-07:00
get right type for initgroups(). No functional change.
- - - - -
66a811d5 by Gary E. Miller at 2017-03-31T19:59:04-07:00
Make 4 implicit casts to be explicit.
No functional changes.
- - - - -
f3e70d86 by Gary E. Miller at 2017-03-31T20:05:41-07:00
Change implicit casts to explicit, no functional change.
- - - - -
460c51e6 by Gary E. Miller at 2017-03-31T20:11:45-07:00
Change implicit casts to explicit.
No functional changes.
- - - - -
642f1e3e by Gary E. Miller at 2017-03-31T20:14:34-07:00
Change two implicit xpacsts to explicit.
- - - - -
3915a442 by Gary E. Miller at 2017-03-31T20:24:44-07:00
Add missing cast.
- - - - -
9bb70a84 by Gary E. Miller at 2017-03-31T20:25:03-07:00
Add missing cast.
Only 298 more casts to find and fix!
- - - - -
17 changed files:
- attic/sht.c
- include/ntp_types.h
- libntp/atolfp.c
- libntp/clocktime.c
- libntp/netof.c
- libntp/recvbuff.c
- libparse/clk_varitext.c
- ntpd/ntp_sandbox.c
- ntpd/refclock_neoclock.c
- tests/libntp/clocktime.c
- tests/libntp/lfpfunc.c
- tests/libntp/lfptest.h
- tests/libntp/lfptostr.c
- tests/libntp/macencrypt.c
- tests/libntp/prettydate.c
- tests/unity/unity.c
- tests/unity/unity_fixture.c
Changes:
=====================================
attic/sht.c
=====================================
--- a/attic/sht.c
+++ b/attic/sht.c
@@ -189,10 +189,10 @@ again:
p->mode=0;
if (!p->valid) {
p->clockTimeStampSec = clk_sec;
- p->clockTimeStampUSec = clk_frc / 1000; /* truncate! */
+ p->clockTimeStampUSec = (int)(clk_frc / 1000); /* truncate! */
p->clockTimeStampNSec = clk_frc;
p->receiveTimeStampSec = rcv_sec;
- p->receiveTimeStampUSec = rcv_frc / 1000; /* truncate! */
+ p->receiveTimeStampUSec = (int)(rcv_frc / 1000); /* truncate! */
p->receiveTimeStampNSec = rcv_frc;
printf ("%ld.%09u %ld.%09u\n",
(long)p->clockTimeStampSec , p->clockTimeStampNSec ,
=====================================
include/ntp_types.h
=====================================
--- a/include/ntp_types.h
+++ b/include/ntp_types.h
@@ -52,7 +52,7 @@ typedef uint64_t time64_t;
#define time64lo(n) ((uint32_t)((n) & LOW32MASK))
#define settime64lo(n, v) (n) = (((n) & HIGH32MASK) | ((v) & LOW32MASK))
#define time64s(n) ((int64_t)(n))
-#define settime64s(n,v) (n) = ((int64_t)(v))
+#define settime64s(n,v) (n) = ((uint64_t)(v))
#define time64u(n) (n)
#define settime64u(n,v) (n) = (v)
#define negtime64(n) ((uint64_t)((((int64_t)(n)) * -1)))
=====================================
libntp/atolfp.c
=====================================
--- a/libntp/atolfp.c
+++ b/libntp/atolfp.c
@@ -68,7 +68,7 @@ atolfp(
while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) {
dec_i = (dec_i << 3) + (dec_i << 1); /* multiply by 10 */
- dec_i += (ind - digits);
+ dec_i += (unsigned long)(ind - digits);
cp++;
}
@@ -80,7 +80,7 @@ atolfp(
&& (ind = strchr(digits, *cp)) != NULL) {
ndec++;
dec_f = (dec_f << 3) + (dec_f << 1); /* *10 */
- dec_f += (ind - digits);
+ dec_f += (unsigned long)(ind - digits);
cp++;
}
=====================================
libntp/clocktime.c
=====================================
--- a/libntp/clocktime.c
+++ b/libntp/clocktime.c
@@ -80,7 +80,7 @@ clocktime(
*/
if (*yearstart) {
/* -- get time stamp of potential solution */
- test[0] = (uint32_t)(*yearstart) + tmp;
+ test[0] = (uint32_t)(*yearstart) + (uint)tmp;
/* -- calc absolute difference to receive time */
diff[0] = test[0] - rec_ui;
if (diff[0] >= 0x80000000u)
@@ -102,12 +102,12 @@ clocktime(
* around the guess and select the entry with the minimum
* absolute difference to the receive time stamp.
*/
- y = ntp_to_year(rec_ui - tmp);
+ y = ntp_to_year(rec_ui - (uint)tmp);
for (idx = 0; idx < 3; idx++) {
/* -- get year start of potential solution */
ystt[idx] = year_to_ntp(y + idx - 1);
/* -- get time stamp of potential solution */
- test[idx] = ystt[idx] + tmp;
+ test[idx] = ystt[idx] + (uint)tmp;
/* -- calc absolute difference to receive time */
diff[idx] = test[idx] - rec_ui;
if (diff[idx] >= 0x80000000u)
@@ -143,6 +143,6 @@ year_to_ntp(
int32_t year)
{
uint32_t days;
- days = ntpcal_days_in_years(year-1) - DAY_NTP_STARTS + 1;
+ days = (uint32_t)ntpcal_days_in_years(year-1) - DAY_NTP_STARTS + 1;
return days * SECSPERDAY;
}
=====================================
libntp/netof.c
=====================================
--- a/libntp/netof.c
+++ b/libntp/netof.c
@@ -17,11 +17,11 @@ netof(
{
static sockaddr_u netofbuf[8];
static int next_netofbuf;
- uint32_t netnum;
+ uint32_t netnum;
sockaddr_u * netaddr;
netaddr = &netofbuf[next_netofbuf];
- next_netofbuf = (next_netofbuf + 1) % COUNTOF(netofbuf);
+ next_netofbuf = (next_netofbuf + 1) % (int)COUNTOF(netofbuf);
memcpy(netaddr, hostaddr, sizeof(*netaddr));
=====================================
libntp/recvbuff.c
=====================================
--- a/libntp/recvbuff.c
+++ b/libntp/recvbuff.c
@@ -63,7 +63,7 @@ create_buffers(int nbufs)
register recvbuf_t *bufp;
int i, abuf;
- abuf = nbufs + buffer_shortfall;
+ abuf = nbufs + (int)buffer_shortfall;
buffer_shortfall = 0;
#ifndef DEBUG
=====================================
libparse/clk_varitext.c
=====================================
--- a/libparse/clk_varitext.c
+++ b/libparse/clk_varitext.c
@@ -182,12 +182,12 @@ inp_varitext(
if (t->start_found)
{
- if ((rtc = parse_addchar(parseio, ch)) != PARSE_INP_SKIP)
+ if ((rtc = (int)parse_addchar(parseio, ch)) != PARSE_INP_SKIP)
{
parseprintf(DD_PARSE, ("inp_varitext: ABORTED due to too many characters\n"));
memset(t, 0, sizeof(struct varitext));
- return rtc;
+ return (unsigned long)rtc;
}
if (t->end_found)
@@ -197,10 +197,10 @@ inp_varitext(
parseprintf(DD_PARSE, ("inp_varitext: END seen\n"));
memset(t, 0, sizeof(struct varitext));
- if ((rtc = parse_addchar(parseio, 0)) == PARSE_INP_SKIP)
+ if ((rtc = (int)parse_addchar(parseio, 0)) == PARSE_INP_SKIP)
return parse_end(parseio);
else
- return rtc;
+ return (unsigned long)rtc;
}
}
@@ -211,7 +211,7 @@ inp_varitext(
}
- t->previous_ch = ch;
+ t->previous_ch = (unsigned char)ch;
return PARSE_INP_SKIP;
}
=====================================
ntpd/ntp_sandbox.c
=====================================
--- a/ntpd/ntp_sandbox.c
+++ b/ntpd/ntp_sandbox.c
@@ -174,7 +174,7 @@ getgroup:
exit(-1);
}
# endif /* HAVE_SOLARIS_PRIVS */
- if (user && initgroups(user, (int)sw_gid)) {
+ if (user && initgroups(user, (gid_t)sw_gid)) {
msyslog(LOG_ERR, "Cannot initgroups() to user `%s': %m", user);
exit (-1);
}
@@ -193,7 +193,7 @@ getgroup:
}
}
else if (pw)
- if (0 != initgroups(pw->pw_name, (int)pw->pw_gid)) {
+ if (0 != initgroups(pw->pw_name, (gid_t)pw->pw_gid)) {
msyslog(LOG_ERR, "initgroups(<%s>, %d) filed: %m", pw->pw_name, pw->pw_gid);
exit (-1);
}
=====================================
ntpd/refclock_neoclock.c
=====================================
--- a/ntpd/refclock_neoclock.c
+++ b/ntpd/refclock_neoclock.c
@@ -769,10 +769,10 @@ neol_mktime(int year,
}
return (((
(unsigned long)(year/4 - year/100 + year/400 + 367*mon/12 + day) +
- year*365 - 719499
- )*24 + hour /* now have hours */
- )*60 + min /* now have minutes */
- )*60 + sec; /* finally seconds */
+ (uint)year*365 - 719499
+ )*24 + (uint)hour /* now have hours */
+ )*60 + (uint)min /* now have minutes */
+ )*60 + (uint)sec; /* finally seconds */
}
static void
=====================================
tests/libntp/clocktime.c
=====================================
--- a/tests/libntp/clocktime.c
+++ b/tests/libntp/clocktime.c
@@ -171,7 +171,7 @@ TEST(clocktime, AlwaysInLimit) {
for (cyc = 0; cyc < 5; cyc++) {
settime(1900 + cyc * 65, 1, 1, 0, 0, 0);
for (yday = -26000; yday < 26000; yday += ydayinc) {
- whichprime = abs(yday) % COUNTOF(prime_incs);
+ whichprime = abs(yday) % (int)COUNTOF(prime_incs);
ydayinc = prime_incs[whichprime];
for (hour = -204; hour < 204; hour += 2) {
for (minute = -60; minute < 60; minute++) {
=====================================
tests/libntp/lfpfunc.c
=====================================
--- a/tests/libntp/lfpfunc.c
+++ b/tests/libntp/lfpfunc.c
@@ -127,7 +127,7 @@ static const l_fp_w addsub_tab[][3] = {
// trivial identity:
{{0 ,0 }, { 0,0 }, { 0,0}},
// with carry from fraction and sign change:
- {{-1,0x80000000}, { 0,0x80000000}, { 0,0}},
+ {{(uint32_t)-1,0x80000000}, { 0,0x80000000}, { 0,0}},
// without carry from fraction
{{ 1,0x40000000}, { 1,0x40000000}, { 2,0x80000000}},
// with carry from fraction:
@@ -174,7 +174,7 @@ eps(double d)
TEST(lfpfunc, Extraction) {
const uint32_t hi = 0xFFEEDDBB;
const uint32_t lo = 0x66554433;
- l_fp lfp = lfpinit(hi, lo);
+ l_fp lfp = lfpinit_u(hi, lo);
TEST_ASSERT_EQUAL(lfpuint(lfp), hi);
TEST_ASSERT_EQUAL(lfpfrac(lfp), lo);
TEST_ASSERT_EQUAL(lfpsint(lfp), -1122885);
@@ -192,7 +192,8 @@ TEST(lfpfunc, Negation) {
size_t idx = 0;
for (idx = 0; idx < addsub_cnt; ++idx) {
- l_fp op1 = lfpinit(addsub_tab[idx][0].l_ui, addsub_tab[idx][0].l_uf);
+ l_fp op1 = lfpinit_u(addsub_tab[idx][0].l_ui,
+ addsub_tab[idx][0].l_uf);
l_fp op2 = l_fp_negate(op1);
l_fp sum = op1 + op2;
@@ -210,7 +211,8 @@ TEST(lfpfunc, Absolute) {
size_t idx = 0;
for (idx = 0; idx < addsub_cnt; ++idx) {
- l_fp op1 = lfpinit(addsub_tab[idx][0].l_ui, addsub_tab[idx][0].l_uf);
+ l_fp op1 = lfpinit_u(addsub_tab[idx][0].l_ui,
+ addsub_tab[idx][0].l_uf);
l_fp op2 = l_fp_abs(op1);
TEST_ASSERT_TRUE(l_fp_signum(op2) >= 0);
@@ -226,7 +228,7 @@ TEST(lfpfunc, Absolute) {
// There is one special case we have to check: the minimum
// value cannot be negated, or, to be more precise, the
// negation reproduces the original pattern.
- l_fp minVal = lfpinit(0x80000000, 0x00000000);
+ l_fp minVal = lfpinit_u(0x80000000, 0x00000000);
l_fp minAbs = l_fp_abs(minVal);
TEST_ASSERT_EQUAL(-1, l_fp_signum(minVal));
@@ -250,7 +252,8 @@ TEST(lfpfunc, FDF_RoundTrip) {
// that limit.
for (idx = 0; idx < addsub_cnt; ++idx) {
- l_fp op1 = lfpinit(addsub_tab[idx][0].l_ui, addsub_tab[idx][0].l_uf);
+ l_fp op1 = lfpinit_u(addsub_tab[idx][0].l_ui,
+ addsub_tab[idx][0].l_uf);
double op2 = lfptod(op1);
l_fp op3 = dtolfp(op2);
@@ -274,8 +277,8 @@ TEST(lfpfunc, SignedRelOps) {
size_t lc ;
for (lc = addsub_tot - 1; lc; --lc, ++tv) {
- l_fp op1 = lfpinit(tv[0].l_ui, tv[0].l_uf);
- l_fp op2 = lfpinit(tv[1].l_ui, tv[1].l_uf);
+ l_fp op1 = lfpinit_u(tv[0].l_ui, tv[0].l_uf);
+ l_fp op2 = lfpinit_u(tv[1].l_ui, tv[1].l_uf);
int cmp = l_fp_scmp(op1, op2);
switch (cmp) {
@@ -304,8 +307,8 @@ TEST(lfpfunc, UnsignedRelOps) {
size_t lc;
for (lc = addsub_tot - 1; lc; --lc, ++tv) {
- l_fp op1 = lfpinit(tv[0].l_ui, tv[0].l_uf);
- l_fp op2 = lfpinit(tv[1].l_ui, tv[1].l_uf);
+ l_fp op1 = lfpinit_u(tv[0].l_ui, tv[0].l_uf);
+ l_fp op2 = lfpinit_u(tv[1].l_ui, tv[1].l_uf);
int cmp = l_fp_ucmp(op1, op2);
switch (cmp) {
=====================================
tests/libntp/lfptest.h
=====================================
--- a/tests/libntp/lfptest.h
+++ b/tests/libntp/lfptest.h
@@ -12,11 +12,11 @@ static bool IsEqual(const l_fp *expected, const l_fp *actual) {
}
}
-static const int32_t HALF = -2147483647L - 1L;
-static const int32_t HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
-static const int32_t HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
-static const int32_t QUARTER = 1073741824L;
-static const int32_t QUARTER_PROMILLE_APPRX = 1073742L;
+static const uint32_t HALF = 2147483648U; // (1 << 31)
+static const uint32_t HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
+static const uint32_t HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
+static const uint32_t QUARTER = 1073741824U; // (1 << 30)
+static const uint32_t QUARTER_PROMILLE_APPRX = 1073742U;
#endif /* GUARD_NTP_TESTS_LFPTEST_H */
=====================================
tests/libntp/lfptostr.c
=====================================
--- a/tests/libntp/lfptostr.c
+++ b/tests/libntp/lfptostr.c
@@ -22,11 +22,11 @@ TEST_TEAR_DOWN(lfptostr) {}
static const int LFP_MAX_PRECISION = 10;
static const int LFP_MAX_PRECISION_MS = 7;
-static const int ONE_FOURTH = 1073741824; // (1 << 30)
-static const int HALF = (1 << 31);
-static const int THREE_FOURTH = -1073741824;
-static const int HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
-static const int HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
+static const uint32_t ONE_FOURTH = 1073741824U; // (1 << 30)
+static const uint32_t HALF = 2147483648U; // (1 << 31)
+static const uint32_t THREE_FOURTH = 3221225472U;
+static const uint32_t HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
+static const uint32_t HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
TEST(lfptostr, PositiveInteger) {
l_fp test = lfpinit(200, 0); // exact 200.0000000000
@@ -103,17 +103,17 @@ TEST(lfptostr, MillisecondsRoundingDown) {
}
TEST(lfptostr, UnsignedInteger) {
- l_fp test1 = lfpinit(3000000000UL, 0);
- l_fp test2 = lfpinit(3000000UL, 0x80000000);
- l_fp test3 = lfpinit(13UL, 0xC0000000);
- l_fp test4 = lfpinit(13UL, 0x028F5C28);
-
- l_fp test5 = lfpinit(4212665562UL, 0x3C6BE7E6);
- l_fp test6 = lfpinit(4212665562UL, 0x36222683);
- l_fp test7 = lfpinit(4212665562UL, 0xBD3F2F5A);
- l_fp test8a = lfpinit(1444359386UL, 0x2E0C7582);
- l_fp test8b = lfpinit(1444359386UL, 0x2E0C7583);
- l_fp test9 = lfpinit(3660323067UL, 0x1CD3101C);
+ l_fp test1 = lfpinit(3000000000L, 0);
+ l_fp test2 = lfpinit(3000000L, 0x80000000);
+ l_fp test3 = lfpinit(13L, 0xC0000000);
+ l_fp test4 = lfpinit(13L, 0x028F5C28);
+
+ l_fp test5 = lfpinit(4212665562L, 0x3C6BE7E6);
+ l_fp test6 = lfpinit(4212665562L, 0x36222683);
+ l_fp test7 = lfpinit(4212665562L, 0xBD3F2F5A);
+ l_fp test8a = lfpinit(1444359386L, 0x2E0C7582);
+ l_fp test8b = lfpinit(1444359386L, 0x2E0C7583);
+ l_fp test9 = lfpinit(3660323067L, 0x1CD3101C);
TEST_ASSERT_EQUAL_STRING("3000000000.0", ulfptoa(test1, 1));
TEST_ASSERT_EQUAL_STRING("3000000000.000000", ulfptoa(test1, 6));
=====================================
tests/libntp/macencrypt.c
=====================================
--- a/tests/libntp/macencrypt.c
+++ b/tests/libntp/macencrypt.c
@@ -81,7 +81,7 @@ TEST(macencrypt, IPv6AddressToRefId) {
SET_AF(&addr, AF_INET6);
SET_SOCK_ADDR6(&addr, address);
- const int expected = htonl(0x52fdcf75);
+ const uint expected = htonl(0x52fdcf75);
TEST_ASSERT_EQUAL(expected, addr2refid(&addr));
}
=====================================
tests/libntp/prettydate.c
=====================================
--- a/tests/libntp/prettydate.c
+++ b/tests/libntp/prettydate.c
@@ -16,7 +16,7 @@ TEST_TEAR_DOWN(prettydate) {}
static const uint32_t HALF = 2147483648UL;
TEST(prettydate, ConstantDate) {
- l_fp time = lfpinit(3485080800UL, HALF); // 2010-06-09 14:00:00.5
+ l_fp time = lfpinit(3485080800L, HALF); // 2010-06-09 14:00:00.5
TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 2010-06-09T14:00:00.500Z", gmprettydate(time));
}
=====================================
tests/unity/unity.c
=====================================
--- a/tests/unity/unity.c
+++ b/tests/unity/unity.c
@@ -169,8 +169,8 @@ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T s
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
- _U_SINT divisor = 1;
- _U_SINT next_divisor;
+ _U_UINT divisor = 1;
+ _U_UINT next_divisor;
_U_UINT number;
if (number_to_print == (1l << (UNITY_LONG_WIDTH-1)))
@@ -204,7 +204,7 @@ void UnityPrintNumber(const _U_SINT number_to_print)
// now mod and print, then divide divisor
do
{
- UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
+ UNITY_OUTPUT_CHAR((int)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
=====================================
tests/unity/unity_fixture.c
=====================================
--- a/tests/unity/unity_fixture.c
+++ b/tests/unity/unity_fixture.c
@@ -87,7 +87,7 @@ void UnityTestRunner(unityfunction* setup,
Unity.CurrentTestFailed = 0;
Unity.TestFile = file;
Unity.CurrentTestName = printableName;
- Unity.CurrentTestLineNumber = line;
+ Unity.CurrentTestLineNumber = (_U_UINT)line;
if (!UnityFixture.Verbose)
UNITY_OUTPUT_CHAR('.');
else
@@ -374,7 +374,7 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
{
if (*(argv[i]) >= '0' && *(argv[i]) <= '9')
{
- UnityFixture.RepeatCount = atoi(argv[i]);
+ UnityFixture.RepeatCount = (unsigned int)atoi(argv[i]);
i++;
}
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/1110a0fbb8df95346e406c39bfed4ebc16b99173...9bb70a84a34de229135d6eec87e5568719bfc13f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170401/0fc2d7ef/attachment.html>
More information about the vc
mailing list