[Top][All Lists]

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

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

From: Julian Foad
Subject: Re: src/kwset.c (kwsincr): Replace arbitrary array size by proper value
Date: Mon, 04 Jul 2005 20:36:41 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b) Gecko/20050217

Charles Levert wrote:
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!"

I don't much like that "#error". For one thing, I think we can just assume that CHAR_BIT is not less than 4. For another thing, we have no precedent for using "#error" elsewhere; I don't know what our conditions for supporting pre-ANSI-C compilers are but I think there is still a conscious attempt to support them where possible, by avoiding pre-ANSI-C features unless they are really useful or really easy to work around.

 /* 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];

I guess you could make this change now without the "#if ... #error" part.

- Julian

reply via email to

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