Skip to contentSkip to conversation

Doc: networking: txtimestamp: fix printf format warning

PATCH Superseded Frans Klaver 2 participants 3 messages Jun 3, 2015 – Jun 4, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Doc: networking: txtimestamp: fix printf format warning

Documentation/networking/timestamping/txtimestamp.c: In function ‘__print_timestamp’:
Documentation/networking/timestamping/txtimestamp.c:99:3: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int64_t’ [-Wformat=]
fprintf(stderr, " (%+ld us)", cur_ms - prev_ms);

int64_t differs per platform, so a cast is required.

---
 Documentation/networking/timestamping/txtimestamp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/networking/timestamping/txtimestamp.c +2 -1
index 8217510..2d107c1 100644
@@ -96,7 +96,8 @@ static void __print_timestamp(const char *name, struct timespec *cur,
 		prev_ms = (long) ts_prev.tv_sec * 1000 * 1000;
 		prev_ms += ts_prev.tv_nsec / 1000;
 
-		fprintf(stderr, "  (%+ld us)", cur_ms - prev_ms);
+		fprintf(stderr, "  (%+lld us)",
+			(long long int)(cur_ms - prev_ms));
 	}
 
 	ts_prev = *cur;
Signature · 1 line
2.4.0
#1 lore raw
Quoted 5 lines · Frans Klaver

Documentation/networking/timestamping/txtimestamp.c: In function ‘__print_timestamp’:
Documentation/networking/timestamping/txtimestamp.c:99:3: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int64_t’ [-Wformat=]
fprintf(stderr, " (%+ld us)", cur_ms - prev_ms);

int64_t differs per platform, so a cast is required.

No cast is needed. Use PRId64 in the format string instead.

Thanks,
Richard

#2 lore raw
Quoted 11 lines · Richard Cochran
Quoted 1 line · Frans Klaver

Documentation/networking/timestamping/txtimestamp.c: In function

‘__print_timestamp’:

Quoted 1 line

Documentation/networking/timestamping/txtimestamp.c:99:3: warning:

format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int64_t’ [-Wformat=]

Quoted 3 lines
   fprintf(stderr, "  (%+ld us)", cur_ms - prev_ms);

int64_t differs per platform, so a cast is required.

No cast is needed. Use PRId64 in the format string instead.

Wow, I can't believe I've never run into those...

Will resend.

Thanks,
Frans