Skip to content

Commit 975ea36

Browse files
committed
Fix warnings when building for 32-bit and defining _TIME_BITS=64
The warnings, given by clang with -Wshorten-64-to-32, were: ./util-print.c:306:48: warning: implicit conversion loses integer precision: 'const __suseconds64_t' (aka 'const long long') to 'long' [-Wshorten-64-to-32] ts_date_hmsfrac_print(ndo, tvp->tv_sec, tvp->tv_usec, ~~~~~~~~~~~~~~~~~~~~~ ~~~~~^~~~~~~ ./util-print.c:306:35: warning: implicit conversion loses integer precision: 'const __time64_t' (aka 'const long long') to 'long' [-Wshorten-64-to-32] ts_date_hmsfrac_print(ndo, tvp->tv_sec, tvp->tv_usec, ~~~~~~~~~~~~~~~~~~~~~ ~~~~~^~~~~~ ./util-print.c:315:40: warning: implicit conversion loses integer precision: 'const __suseconds64_t' (aka 'const long long') to 'long' [-Wshorten-64-to-32] ts_unix_print(ndo, tvp->tv_sec, tvp->tv_usec); ~~~~~~~~~~~~~ ~~~~~^~~~~~~ ./util-print.c:315:27: warning: implicit conversion loses integer precision: 'const __time64_t' (aka 'const long long') to 'long' [-Wshorten-64-to-32] ts_unix_print(ndo, tvp->tv_sec, tvp->tv_usec); ~~~~~~~~~~~~~ ~~~~~^~~~~~ ./util-print.c:346:58: warning: implicit conversion loses integer precision: '__suseconds64_t' (aka 'long long') to 'long' [-Wshorten-64-to-32] ts_date_hmsfrac_print(ndo, tv_result.tv_sec, tv_result.tv_usec, ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~^~~~~~~ ./util-print.c:346:40: warning: implicit conversion loses integer precision: '__time64_t' (aka 'long long') to 'long' [-Wshorten-64-to-32] ts_date_hmsfrac_print(ndo, tv_result.tv_sec, tv_result.tv_usec, ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~^~~~~~ ./util-print.c:355:48: warning: implicit conversion loses integer precision: 'const __suseconds64_t' (aka 'const long long') to 'long' [-Wshorten-64-to-32] ts_date_hmsfrac_print(ndo, tvp->tv_sec, tvp->tv_usec, ~~~~~~~~~~~~~~~~~~~~~ ~~~~~^~~~~~~ ./util-print.c:355:35: warning: implicit conversion loses integer precision: 'const __time64_t' (aka 'const long long') to 'long' [-Wshorten-64-to-32] ts_date_hmsfrac_print(ndo, tvp->tv_sec, tvp->tv_usec, ~~~~~~~~~~~~~~~~~~~~~ ~~~~~^~~~~~
1 parent e6d9535 commit 975ea36

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

util-print.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,25 @@ nd_printjnp(netdissect_options *ndo, const u_char *s, u_int n)
214214
* Print the timestamp .FRAC part (Microseconds/nanoseconds)
215215
*/
216216
static void
217-
ts_frac_print(netdissect_options *ndo, long usec)
217+
ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
218218
{
219219
#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
220220
switch (ndo->ndo_tstamp_precision) {
221221

222222
case PCAP_TSTAMP_PRECISION_MICRO:
223-
ND_PRINT(".%06u", (unsigned)usec);
223+
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
224224
break;
225225

226226
case PCAP_TSTAMP_PRECISION_NANO:
227-
ND_PRINT(".%09u", (unsigned)usec);
227+
ND_PRINT(".%09u", (unsigned)tv->tv_usec);
228228
break;
229229

230230
default:
231231
ND_PRINT(".{unknown}");
232232
break;
233233
}
234234
#else
235-
ND_PRINT(".%06u", (unsigned)usec);
235+
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
236236
#endif
237237
}
238238

@@ -242,23 +242,22 @@ ts_frac_print(netdissect_options *ndo, long usec)
242242
* if date_flag == WITH_DATE print YY:MM:DD before HH:MM:SS.FRAC
243243
*/
244244
static void
245-
ts_date_hmsfrac_print(netdissect_options *ndo, long sec, long usec,
245+
ts_date_hmsfrac_print(netdissect_options *ndo, const struct timeval *tv,
246246
enum date_flag date_flag, enum time_flag time_flag)
247247
{
248-
time_t Time = sec;
249248
struct tm *tm;
250249
char timebuf[32];
251250
const char *timestr;
252251

253-
if ((unsigned)sec & 0x80000000) {
252+
if ((unsigned)tv->tv_sec & 0x80000000) {
254253
ND_PRINT("[Error converting time]");
255254
return;
256255
}
257256

258257
if (time_flag == LOCAL_TIME)
259-
tm = localtime(&Time);
258+
tm = localtime(&tv->tv_sec);
260259
else
261-
tm = gmtime(&Time);
260+
tm = gmtime(&tv->tv_sec);
262261

263262
if (date_flag == WITH_DATE) {
264263
timestr = nd_format_time(timebuf, sizeof(timebuf),
@@ -269,22 +268,22 @@ ts_date_hmsfrac_print(netdissect_options *ndo, long sec, long usec,
269268
}
270269
ND_PRINT("%s", timestr);
271270

272-
ts_frac_print(ndo, usec);
271+
ts_frac_print(ndo, tv);
273272
}
274273

275274
/*
276275
* Print the timestamp - Unix timeval style, as SECS.FRAC.
277276
*/
278277
static void
279-
ts_unix_print(netdissect_options *ndo, long sec, long usec)
278+
ts_unix_print(netdissect_options *ndo, const struct timeval *tv)
280279
{
281-
if ((unsigned)sec & 0x80000000) {
280+
if ((unsigned)tv->tv_sec & 0x80000000) {
282281
ND_PRINT("[Error converting time]");
283282
return;
284283
}
285284

286-
ND_PRINT("%u", (unsigned)sec);
287-
ts_frac_print(ndo, usec);
285+
ND_PRINT("%u", (unsigned)tv->tv_sec);
286+
ts_frac_print(ndo, tv);
288287
}
289288

290289
/*
@@ -302,16 +301,15 @@ ts_print(netdissect_options *ndo,
302301
switch (ndo->ndo_tflag) {
303302

304303
case 0: /* Default */
305-
ts_date_hmsfrac_print(ndo, tvp->tv_sec, tvp->tv_usec,
306-
WITHOUT_DATE, LOCAL_TIME);
304+
ts_date_hmsfrac_print(ndo, tvp, WITHOUT_DATE, LOCAL_TIME);
307305
ND_PRINT(" ");
308306
break;
309307

310308
case 1: /* No time stamp */
311309
break;
312310

313311
case 2: /* Unix timeval style */
314-
ts_unix_print(ndo, tvp->tv_sec, tvp->tv_usec);
312+
ts_unix_print(ndo, tvp);
315313
ND_PRINT(" ");
316314
break;
317315

@@ -342,17 +340,15 @@ ts_print(netdissect_options *ndo,
342340
netdissect_timevalsub(tvp, &tv_ref, &tv_result, nano_prec);
343341

344342
ND_PRINT((negative_offset ? "-" : " "));
345-
ts_date_hmsfrac_print(ndo, tv_result.tv_sec, tv_result.tv_usec,
346-
WITHOUT_DATE, UTC_TIME);
343+
ts_date_hmsfrac_print(ndo, &tv_result, WITHOUT_DATE, UTC_TIME);
347344
ND_PRINT(" ");
348345

349346
if (ndo->ndo_tflag == 3)
350347
tv_ref = *tvp; /* set timestamp for previous packet */
351348
break;
352349

353350
case 4: /* Date + Default */
354-
ts_date_hmsfrac_print(ndo, tvp->tv_sec, tvp->tv_usec,
355-
WITH_DATE, LOCAL_TIME);
351+
ts_date_hmsfrac_print(ndo, tvp, WITH_DATE, LOCAL_TIME);
356352
ND_PRINT(" ");
357353
break;
358354
}

0 commit comments

Comments
 (0)