From 72cb81151f2262bc2062cc1cdf7d4a7e768c4b15 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 10 May 2016 22:05:53 +0000 Subject: [PATCH] tests: add print_quoted_memory function to libtests * tests/print_quoted_string.c (print_quoted_memory): New function. (print_quoted_string): Use it. * tests/tests.h (print_quoted_memory): New prototype. --- tests/print_quoted_string.c | 12 ++++++++++-- tests/tests.h | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/print_quoted_string.c b/tests/print_quoted_string.c index 18a9ccfb..3ad86024 100644 --- a/tests/print_quoted_string.c +++ b/tests/print_quoted_string.c @@ -2,6 +2,7 @@ #include #include +#include /* * Based on string_quote() from util.c. @@ -10,11 +11,18 @@ void print_quoted_string(const char *instr) +{ + print_quoted_memory(instr, strlen(instr)); +} + +void +print_quoted_memory(const char *instr, const size_t len) { const unsigned char *str = (const unsigned char*) instr; - int c; + size_t i; - while ((c = *(str++))) { + for (i = 0; i < len; ++i) { + const int c = str[i]; switch (c) { case '\"': printf("\\\""); diff --git a/tests/tests.h b/tests/tests.h index 8c466bfd..9909222f 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -78,9 +78,12 @@ const char *hexquote_strndup(const char *, size_t); /* Return inode number of socket descriptor. */ unsigned long inode_of_sockfd(int); -/* Print string in quoted form. */ +/* Print string in a quoted form. */ void print_quoted_string(const char *); +/* Print memory in a quoted form. */ +void print_quoted_memory(const char *, size_t); + /* Check whether given uid matches kernel overflowuid. */ void check_overflowuid(const int); -- 2.40.0