From: Dmitry V. Levin Date: Sat, 8 Jul 2017 14:57:44 +0000 (+0000) Subject: tests: fix print_quoted_hex output of bytes with high bit set X-Git-Tag: v4.19~316 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17d002a252f75dc27d524b257b393afc7afb0521;p=strace tests: fix print_quoted_hex output of bytes with high bit set * tests/tests.h (print_quoted_memory, print_quoted_hex): Change the type of first argument from "const char *" to "const void *". * tests/print_quoted_string.c: Likewise. (print_quoted_hex): Print bytes as unsigned char objects to avoid unwanted sign extension. * tests/netlink_protocol.c (send_query): Remove the cast of print_quoted_hex first argument which is now redundant. --- diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c index a3e09cb9..ee5bf0fe 100644 --- a/tests/netlink_protocol.c +++ b/tests/netlink_protocol.c @@ -156,7 +156,7 @@ send_query(const int fd) printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x" ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}, ", fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP); - print_quoted_hex((void *) &reqs->req2.nlh, + print_quoted_hex(&reqs->req2.nlh, sizeof(reqs->req2) - sizeof(req->nlh)); printf("], %u, MSG_DONTWAIT, NULL, 0) = %s\n", (unsigned) (sizeof(*reqs) - sizeof(req->nlh)), errstr); diff --git a/tests/print_quoted_string.c b/tests/print_quoted_string.c index 9103eed6..dcfcfa0e 100644 --- a/tests/print_quoted_string.c +++ b/tests/print_quoted_string.c @@ -16,7 +16,7 @@ print_quoted_string(const char *instr) } void -print_quoted_memory(const char *instr, const size_t len) +print_quoted_memory(const void *const instr, const size_t len) { const unsigned char *str = (const unsigned char *) instr; size_t i; @@ -77,8 +77,9 @@ print_quoted_memory(const char *instr, const size_t len) } void -print_quoted_hex(const char *str, const size_t len) +print_quoted_hex(const void *const instr, const size_t len) { + const unsigned char *str = instr; size_t i; printf("\""); diff --git a/tests/tests.h b/tests/tests.h index bc7dc988..633461b3 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -135,10 +135,10 @@ unsigned long inode_of_sockfd(int); void print_quoted_string(const char *); /* Print memory in a quoted form. */ -void print_quoted_memory(const char *, size_t); +void print_quoted_memory(const void *, size_t); /* Print memory in a hexquoted form. */ -void print_quoted_hex(const char *, size_t); +void print_quoted_hex(const void *, size_t); /* Print time_t and nanoseconds in symbolic format. */ void print_time_t_nsec(time_t, unsigned long long, int);