(compile_range): Avoid warning in casts for range_start/end.
[gnulib.git] / regex.c
diff --git a/regex.c b/regex.c
index bd9ad6f..82ab3d0 100644 (file)
--- a/regex.c
+++ b/regex.c
@@ -898,8 +898,8 @@ static const char *re_error_msg[] =
    ralloc heap) shift the data out from underneath the regexp
    routines.
 
-   Here's another reason to avoid allocation: Emacs insists on
-   processing input from X in a signal handler; processing X input may
+   Here's another reason to avoid allocation: Emacs 
+   processes input from X in a signal handler; processing X input may
    call malloc; if input arrives while a matching routine is calling
    malloc, then we're scrod.  But Emacs can't just block input while
    calling matching routines; then we don't notice interrupts when
@@ -910,8 +910,9 @@ static const char *re_error_msg[] =
 /* Normally, this is fine.  */
 #define MATCH_MAY_ALLOCATE
 
-/* But under some circumstances, it's not.  */
-#if defined (emacs) || (defined (REL_ALLOC) && defined (C_ALLOCA))
+/* The match routines may not allocate if (1) they would do it with malloc
+   and (2) it's not safe for htem to use malloc.  */
+#if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && (defined (emacs) || defined (REL_ALLOC))
 #undef MATCH_MAY_ALLOCATE
 #endif
 
@@ -1492,12 +1493,7 @@ typedef struct
 
 /* Return, freeing storage we allocated.  */
 #define FREE_STACK_RETURN(value)               \
-do                                             \
-{                                              \
-  free (compile_stack.stack);                  \
-  return value;                                        \
-}                                              \
-while (1)
+  return (free (compile_stack.stack), value)
 
 static reg_errcode_t
 regex_compile (pattern, size, syntax, bufp)
@@ -2710,8 +2706,8 @@ compile_range (p_ptr, pend, translate, syntax, b)
 
      We also want to fetch the endpoints without translating them; the 
      appropriate translation is done in the bit-setting loop below.  */
-  range_start = ((unsigned char *) p)[-2];
-  range_end   = ((unsigned char *) p)[0];
+  range_start = ((unsigned const char *) p)[-2];
+  range_end   = ((unsigned const char *) p)[0];
 
   /* Have to increment the pointer into the pattern string, so the
      caller isn't still at the ending character.  */
@@ -4297,7 +4293,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
 #endif
 
                 if ((re_opcode_t) p1[3] == exactn
-                   && ! (p2[1] * BYTEWIDTH > p1[4]
+                   && ! ((int) p2[1] * BYTEWIDTH > (int) p1[4]
                          && (p2[1 + p1[4] / BYTEWIDTH]
                              & (1 << (p1[4] % BYTEWIDTH)))))
                   {
@@ -4311,9 +4307,9 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
                    int idx;
                    /* We win if the charset_not inside the loop
                       lists every character listed in the charset after.  */
-                   for (idx = 0; idx < p2[1]; idx++)
+                   for (idx = 0; idx < (int) p2[1]; idx++)
                      if (! (p2[2 + idx] == 0
-                            || (idx < p1[4]
+                            || (idx < (int) p1[4]
                                 && ((p2[2 + idx] & ~ p1[5 + idx]) == 0))))
                        break;
 
@@ -4328,7 +4324,9 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
                    int idx;
                    /* We win if the charset inside the loop
                       has no overlap with the one after the loop.  */
-                   for (idx = 0; idx < p2[1] && idx < p1[4]; idx++)
+                   for (idx = 0;
+                        idx < (int) p2[1] && idx < (int) p1[4];
+                        idx++)
                      if ((p2[2 + idx] & p1[5 + idx]) != 0)
                        break;