summaryrefslogtreecommitdiff
path: root/x11/mlterm/patches/patch-ah
blob: fc9cbbb92f21f0d4fc553314f453942a35a6be80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$NetBSD: patch-ah,v 1.1 2006/12/19 07:53:57 wiz Exp $

safer DIGIT_STR_LEN().

http://mlterm.cvs.sourceforge.net/mlterm/mlterm/kiklib/src/kik_util.h?r1=1.4&r2=1.5&view=patch

--- kiklib/src/kik_util.h.orig	2002/02/02 09:20:27	1.4
+++ kiklib/src/kik_util.h	2006/10/13 16:13:42	1.5
@@ -10,19 +10,20 @@
 
 #define  K_MIN(n1,n2)  ((n1) > (n2) ? (n2) : (n1))
 
-/*
- * char  : 0 - 256 (3)
- * int16 : 0 - 65536 (5)
- * int32 : 0 - 4294967296 (10)
- * int64 : 0 - 18446744073709551616 (20)
+/* TYPE: MIN(signed) -- MAX(unsigned) (number of bytes needed)
+ * char  : -128 -- 256 (4)
+ * int16 : -32768 -- 65536 (6)
+ * int32 : -2147483648 -- 4294967296 (11)
+ * int64 : -9223372036854775808 -- 18446744073709551616 (20)
  * 
- * 40 is evenly selected in other cases just to be sure.
+ * Since log10(2^8) = 2.4..., (sizeof(n)*3) is large enough
+ * for all n >= 2.
  */
 #define  DIGIT_STR_LEN(n)  \
-	((sizeof(n) == 1) ? 3 : \
-	(sizeof(n) == 2) ? 5 : \
-	(sizeof(n) == 4) ? 10 : \
-	(sizeof(n) == 8) ? 20 : 40)
+	((sizeof(n) == 1) ? 4 : \
+	(sizeof(n) == 2) ? 6 : \
+	(sizeof(n) == 4) ? 11 : \
+	(sizeof(n) == 8) ? 20 : (sizeof(n)*3))
 
 
 #endif