summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmcc <mmcc@openbsd.org>2016-01-26 01:51:06 +0000
committermmcc <mmcc@openbsd.org>2016-01-26 01:51:06 +0000
commit5d322bd670648ef6297bfef40de539d8f88674be (patch)
treeceb5077b33da17013c7746b8f4ef4825c29719cc
parentTwo more for the attic. (diff)
downloadwireguard-openbsd-5d322bd670648ef6297bfef40de539d8f88674be.tar.xz
wireguard-openbsd-5d322bd670648ef6297bfef40de539d8f88674be.zip
Remove a fancy macro that calculates the necessary buffer size for
int-to-str conversions and just use constants instead. The only binary change is caused by using an unnecessarily large buffer for an int. This is a consequence of simplifying some code that will be gone soon. ok nicm@
-rw-r--r--usr.bin/less/less.h7
-rw-r--r--usr.bin/less/line.c2
-rw-r--r--usr.bin/less/output.c6
-rw-r--r--usr.bin/less/prompt.c4
4 files changed, 6 insertions, 13 deletions
diff --git a/usr.bin/less/less.h b/usr.bin/less/less.h
index cb3d31ca3df..9a0946489dc 100644
--- a/usr.bin/less/less.h
+++ b/usr.bin/less/less.h
@@ -58,13 +58,6 @@
#endif
/*
- * Upper bound on the string length of an integer converted to string.
- * 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
- * add 1 for integer division truncation; add 1 more for a minus sign.
- */
-#define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 1 + 1)
-
-/*
* Special types and constants.
*/
typedef unsigned long LWCHAR;
diff --git a/usr.bin/less/line.c b/usr.bin/less/line.c
index ab6f701921e..757ec904627 100644
--- a/usr.bin/less/line.c
+++ b/usr.bin/less/line.c
@@ -175,7 +175,7 @@ plinenum(off_t pos)
* if the -N option is set.
*/
if (linenums == OPT_ONPLUS) {
- char buf[INT_STRLEN_BOUND(pos) + 2];
+ char buf[23];
int n;
postoa(linenum, buf, sizeof(buf));
diff --git a/usr.bin/less/output.c b/usr.bin/less/output.c
index 8110a1a27e5..eaad99088f9 100644
--- a/usr.bin/less/output.c
+++ b/usr.bin/less/output.c
@@ -135,7 +135,7 @@ void \
funcname(type num, char *buf, size_t len) \
{ \
int neg = (num < 0); \
- char tbuf[INT_STRLEN_BOUND(num)+2]; \
+ char tbuf[23]; \
char *s = tbuf + sizeof (tbuf); \
if (neg) \
num = -num; \
@@ -157,7 +157,7 @@ TYPE_TO_A_FUNC(inttoa, int)
static int
iprint_int(int num)
{
- char buf[INT_STRLEN_BOUND(num)];
+ char buf[11];
inttoa(num, buf, sizeof (buf));
putstr(buf);
@@ -170,7 +170,7 @@ iprint_int(int num)
static int
iprint_linenum(off_t num)
{
- char buf[INT_STRLEN_BOUND(num)];
+ char buf[21];
postoa(num, buf, sizeof(buf));
putstr(buf);
diff --git a/usr.bin/less/prompt.c b/usr.bin/less/prompt.c
index e321e36c2d5..fb0c58066b9 100644
--- a/usr.bin/less/prompt.c
+++ b/usr.bin/less/prompt.c
@@ -118,7 +118,7 @@ ap_char(char c)
static void
ap_pos(off_t pos)
{
- char buf[INT_STRLEN_BOUND(pos) + 2];
+ char buf[23];
postoa(pos, buf, sizeof(buf));
ap_str(buf);
@@ -130,7 +130,7 @@ ap_pos(off_t pos)
static void
ap_int(int num)
{
- char buf[INT_STRLEN_BOUND(num) + 2];
+ char buf[13];
inttoa(num, buf, sizeof buf);
ap_str(buf);