bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

src/kwset.c (kwsincr): Replace arbitrary array size by proper value


From: Charles Levert
Subject: src/kwset.c (kwsincr): Replace arbitrary array size by proper value
Date: Mon, 4 Jul 2005 11:57:31 -0400
User-agent: Mutt/1.4.1i

Proposed patch; I'll write a ChangeLog entry if
it's accepted.

I have checked that this will hold for CHAR_BIT
up to 1023.  Custom tools used for checking
this available upon request (part analytical,
part experimental).



--- src/kwset.c 2005-07-04 01:14:37 -0400
+++ src/kwset.c 2005-07-04 11:45:33 -0400
@@ -121,6 +121,14 @@ kwsalloc (char const *trans)
   return (kwset_t) kwset;
 }
 
+/* This upper bound is valid for CHAR_BIT >= 4 and
+   exact for CHAR_BIT in { 4..11, 13, 15, 17, 19 }. */
+#if CHAR_BIT < 4
+#error "CHAR_BIT is smaller than 4; yeah, right!"
+#else
+#define DEPTH_SIZE (CHAR_BIT + CHAR_BIT/2)
+#endif
+
 /* Add the given string to the contents of the keyword set.  Return NULL
    for success, an error message otherwise. */
 const char *
@@ -131,8 +139,8 @@ kwsincr (kwset_t kws, char const *text, 
   register unsigned char label;
   register struct tree *link;
   register int depth;
-  struct tree *links[12];
-  enum { L, R } dirs[12];
+  struct tree *links[DEPTH_SIZE];
+  enum { L, R } dirs[DEPTH_SIZE];
   struct tree *t, *r, *l, *rl, *lr;
 
   kwset = (struct kwset *) kws;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]