Subject: more 64bit breakage (regexec.c this time)

From: [email-masked]
Date: Mon, 11 Oct 2004 20:35:36 +0100

Package: nvi
Version: 1.79-21

regexec.c breaks in some cases on 64bit boxen.  More accurately, it
sometimes happens to work on these.  The reason is that author had
very odd idea of the way cpp works:

/* macros for manipulating states, small version */
#define states  int
#define states1 states          /* for later use in regexec() decision */
...
/* now undo things */
#undef  states
...
/* macros for manipulating states, large version */
#define states  char *
...
        if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
                return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
        else
                return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));

Note that states1 there will expand to char *, not to int as intended.
As the result, on boxen that have char * bigger than int we can end
up calling the wrong function - one that expects a bitmap with g->nstates
elements to fit into int.  That breaks in all sorts of platform-specific
ways, of course.

E.g. on alpha try the following:
vi
ixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<ESC>:%s/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
and watch what it leaves.  On other platforms breakage might differ -
we are in nasal demon land, since we end up doing left shifts on signed
int by more than the width of int...

Fix is trivial:

diff -urN nvi-1.79.old/regex/regexec.c nvi-1.79/regex/regexec.c
--- nvi-1.79.old/regex/regexec.c	1996-07-09 19:05:53.000000000 -0400
+++ nvi-1.79/regex/regexec.c	2004-10-11 15:01:17.722795992 -0400
@@ -63,7 +63,7 @@
 
 /* macros for manipulating states, small version */
 #define	states	int
-#define	states1	states		/* for later use in regexec() decision */
+typedef	states states1;		/* for later use in regexec() decision */
 #define	CLEAR(v)	((v) = 0)
 #define	SET0(v, n)	((v) &= ~(1 << (n)))
 #define	SET1(v, n)	((v) |= 1 << (n))