From 79acbcf2550f3a55108240558efb8b9c36eb8399 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Tue, 19 Feb 2019 03:10:11 +0100
Subject: [PATCH] util: update dumpstr
Use a buffer of a limited size, use proper type for dump amount, avoid
hard-coding of byte counts, calculate output buffer size more accurately
and minimise its rewriting, pad offset with zeros in accordance
with expected output amount.
* defs.h (dumpstr): Change the type of len argument from int to
kernel_ulong_t.
* macros.h (ROUNDUP_DIV): New macro.
(ROUNDUP): Rewrite using ROUNDUP_DIV.
* util.c (ILOG2_ITER_): New macro.
(ilog2_64, ilog2_32): New functions.
(ilog2_klong): New macro, wrapper around ilog2_32/ilog2_64, so (potentially
more expensive) ilog2_64 is not used for ilog2 calculation
of a kernel_ulong_t-typed variable on architectures with 32-bit kernel long.
(dumpstr): Update.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
---
defs.h | 2 +-
macros.h | 6 +-
util.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
3 files changed, 169 insertions(+), 44 deletions(-)
diff --git a/macros.h b/macros.h
index 7f019480..61abf826 100644
--- a/macros.h
+++ b/macros.h
@@ -28,8 +28,12 @@
#endif
#define CLAMP(val, min, max) MIN(MAX(min, val), max)
+#ifndef ROUNDUP_DIV
+# define ROUNDUP_DIV(val_, div_) (((val_) + (div_) - 1) / (div_))
+#endif
+
#ifndef ROUNDUP
-# define ROUNDUP(val_, div_) ((((val_) + (div_) - 1) / (div_)) * (div_))
+# define ROUNDUP(val_, div_) (ROUNDUP_DIV((val_), (div_)) * (div_))
#endif
#ifndef offsetofend
--
2.13.6