@@ -3,6 +3,7 @@
* Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
*/
+#include <cinttypes>
#include <cstring>
#include <ctime>
#include <sstream>
@@ -354,7 +355,7 @@ void print_timers(struct node *node)
printf("source: %s, ", source.c_str());
if (t.recording_seq)
printf("rec-seq: 0x%x, ", t.recording_seq);
- printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */
+ printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */
}
printf("Total media space available for recording: ");
if (node->state.media_space_available >= 0)
@@ -15,6 +15,7 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p)
{
struct v4l2_timecode *tc=&p->timecode;
- printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, "
+ printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, "
"bytesused=%d, flags=0x%08x, "
"field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n",
- name, (p->timestamp.tv_sec/3600),
+ name, (uint64_t)(p->timestamp.tv_sec/3600),
(int)(p->timestamp.tv_sec/60)%60,
(int)(p->timestamp.tv_sec%60),
- p->timestamp.tv_usec,
+ (uint64_t)p->timestamp.tv_usec,
p->index,
prt_names(p->type,v4l2_type_names),
p->bytesused,p->flags,
Under musl, if a format string has an integer followed by %s, a mismatch between types can cause the second half of the integer to be interpreted by %s. Eg: printf("%d %s", 64bittype, string); will crash, especially on 32-bit big endian. The reason these are cast to uint64_t is because time_t and suseconds_t are 64-bit under musl, even on 32-bit platforms. uint64_t helps avoid any truncation issues that may or may not arise. Signed-off-by: Rosen Penev <rosenp@gmail.com> --- utils/cec-follower/cec-follower.cpp | 3 ++- utils/libv4l2util/v4l2_driver.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)