summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2016-01-20 17:58:56 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-20 20:09:18 -0500
commitad27a7559a85309a4775389d012f3728c92f5eb0 (patch)
tree453c92d12230346cc12442c30edefb669ac8d075 /lib
parenta3d601fcc2f94fd1583053a1b1aea5de66ffc79c (diff)
test_hexdump: replace magic numbers by their meaning
The magic numbers of the length are converted to their actual meaning, such as end of the buffer with and without ASCII part. We don't touch the rest of the magic constants that will be removed in the following commits. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_hexdump.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 940b1d318831..141d031e6a13 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -137,17 +137,26 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii)
137{ 137{
138 char buf[TEST_HEXDUMP_BUF_SIZE]; 138 char buf[TEST_HEXDUMP_BUF_SIZE];
139 const char *t = test_data_1_le[0]; 139 const char *t = test_data_1_le[0];
140 size_t len = 1;
141 int rs = 16, gs = 1;
142 int ae, he, e, r;
140 bool a; 143 bool a;
141 int e, r;
142 144
143 memset(buf, FILL_CHAR, sizeof(buf)); 145 memset(buf, FILL_CHAR, sizeof(buf));
144 146
145 r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, buflen, ascii); 147 r = hex_dump_to_buffer(data_b, len, rs, gs, buf, buflen, ascii);
148
149 /*
150 * Caller must provide the data length multiple of groupsize. The
151 * calculations below are made with that assumption in mind.
152 */
153 ae = rs * 2 /* hex */ + rs / gs /* spaces */ + 1 /* space */ + len /* ascii */;
154 he = (gs * 2 /* hex */ + 1 /* space */) * len / gs - 1 /* no trailing space */;
146 155
147 if (ascii) 156 if (ascii)
148 e = 50; 157 e = ae;
149 else 158 else
150 e = 2; 159 e = he;
151 buf[e + 2] = '\0'; 160 buf[e + 2] = '\0';
152 161
153 if (!buflen) { 162 if (!buflen) {