Re: Char cleanup in lex(1)

2015-10-13 Thread Michael McConville
Theo de Raadt wrote:
> > When scanning for is*() function uses with signed chars, I found that
> > lex(1) uses an unecessary #define for unsigned char. The below diff
> > removes it and fixes an undefined is*() usage or two as well.
> 
> Our tree uses lex pretty much as-is from upstream, so this refactoring
> isn't the way to go.
> 
> If you find an actual bug however.. fix them, using the established
> practice.

Here are just the bug fixes:


Index: misc.c
===
RCS file: /cvs/src/usr.bin/lex/misc.c,v
retrieving revision 1.13
diff -u -p -r1.13 misc.c
--- misc.c  27 Oct 2013 18:31:24 -  1.13
+++ misc.c  13 Oct 2015 14:30:30 -
@@ -109,7 +109,7 @@ char *str;
{
while ( *str )
{
-   if ( ! isascii( (Char) *str ) || ! islower( *str ) )
+   if ( ! isascii( (Char) *str ) || ! islower( (unsigned char) 
*str ) )
return 0;
++str;
}
@@ -125,7 +125,7 @@ char *str;
{
while ( *str )
{
-   if ( ! isascii( (Char) *str ) || ! isupper( *str ) )
+   if ( ! isascii( (Char) *str ) || ! isupper( (unsigned char) 
*str ) )
return 0;
++str;
}
@@ -590,7 +590,7 @@ Char array[];
int sptr = 2;
 
while ( isascii( array[sptr] ) &&
-   isxdigit( (char) array[sptr] ) )
+   isxdigit( array[sptr] ) )
/* Don't increment inside loop control
 * because if isdigit() is a macro it might
 * expand into multiple increments ...



Re: Char cleanup in lex(1)

2015-10-13 Thread Michael McConville
Michael McConville wrote:
> Theo de Raadt wrote:
> > > When scanning for is*() function uses with signed chars, I found that
> > > lex(1) uses an unecessary #define for unsigned char. The below diff
> > > removes it and fixes an undefined is*() usage or two as well.
> > 
> > Our tree uses lex pretty much as-is from upstream, so this refactoring
> > isn't the way to go.
> > 
> > If you find an actual bug however.. fix them, using the established
> > practice.
> 
> Here are just the bug fixes:

Forgot to use Char. New diff:


Index: misc.c
===
RCS file: /cvs/src/usr.bin/lex/misc.c,v
retrieving revision 1.13
diff -u -p -r1.13 misc.c
--- misc.c  27 Oct 2013 18:31:24 -  1.13
+++ misc.c  13 Oct 2015 14:58:40 -
@@ -109,7 +109,7 @@ char *str;
{
while ( *str )
{
-   if ( ! isascii( (Char) *str ) || ! islower( *str ) )
+   if ( ! isascii( (Char) *str ) || ! islower( (Char) *str ) )
return 0;
++str;
}
@@ -125,7 +125,7 @@ char *str;
{
while ( *str )
{
-   if ( ! isascii( (Char) *str ) || ! isupper( *str ) )
+   if ( ! isascii( (Char) *str ) || ! isupper( (Char) *str ) )
return 0;
++str;
}
@@ -590,7 +590,7 @@ Char array[];
int sptr = 2;
 
while ( isascii( array[sptr] ) &&
-   isxdigit( (char) array[sptr] ) )
+   isxdigit( array[sptr] ) )
/* Don't increment inside loop control
 * because if isdigit() is a macro it might
 * expand into multiple increments ...



Re: Char cleanup in lex(1)

2015-10-12 Thread Theo de Raadt
Our tree uses lex pretty much as-is from upstream, so this refactoring
isn't the way to go.

If you find an actual bug however.. fix them, using the established
practice.

> When scanning for is*() function uses with signed chars, I found that
> lex(1) uses an unecessary #define for unsigned char. The below diff
> removes it and fixes an undefined is*() usage or two as well.
> 
> 
> Index: ecs.c
> ===
> RCS file: /cvs/src/usr.bin/lex/ecs.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 ecs.c
> --- ecs.c 4 Jun 2003 17:34:44 -   1.6
> +++ ecs.c 12 Oct 2015 14:13:36 -
> @@ -107,9 +107,9 @@ int fwd[], bck[], num;
>  /* mkeccl - update equivalence classes based on character class xtions
>   *
>   * synopsis
> - *Char ccls[];
> + *unsigned char ccls[];
>   *int lenccl, fwd[llsiz], bck[llsiz], llsiz, NUL_mapping;
> - *void mkeccl( Char ccls[], int lenccl, int fwd[llsiz], int bck[llsiz],
> + *void mkeccl( unsigned char ccls[], int lenccl, int fwd[llsiz], int 
> bck[llsiz],
>   *   int llsiz, int NUL_mapping );
>   *
>   * ccls contains the elements of the character class, lenccl is the
> @@ -120,7 +120,7 @@ int fwd[], bck[], num;
>   */
>  
>  void mkeccl( ccls, lenccl, fwd, bck, llsiz, NUL_mapping )
> -Char ccls[];
> +unsigned char ccls[];
>  int lenccl, fwd[], bck[], llsiz, NUL_mapping;
>   {
>   int cclp, oldec, newec;
> Index: flexdef.h
> ===
> RCS file: /cvs/src/usr.bin/lex/flexdef.h,v
> retrieving revision 1.8
> diff -u -p -r1.8 flexdef.h
> --- flexdef.h 10 Oct 2015 05:47:54 -  1.8
> +++ flexdef.h 12 Oct 2015 14:13:36 -
> @@ -81,7 +81,6 @@
>  
>  /* Always be prepared to generate an 8-bit scanner. */
>  #define CSIZE 256
> -#define Char unsigned char
>  
>  /* Size of input alphabet - should be size of ASCII set. */
>  #ifndef DEFAULT_CSIZE
> @@ -633,7 +632,7 @@ extern int end_of_buffer_state;
>  
>  extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
>  extern int current_maxccls, current_max_ccl_tbl_size;
> -extern Char *ccltbl;
> +extern unsigned char *ccltbl;
>  
>  
>  /* Variables for miscellaneous information:
> @@ -701,10 +700,10 @@ void flex_free PROTO((void*));
>   (char *) reallocate_array( (void *) array, size, sizeof( char ) )
>  
>  #define allocate_Character_array(size) \
> - (Char *) allocate_array( size, sizeof( Char ) )
> + (unsigned char *) allocate_array( size, sizeof( unsigned char ) )
>  
>  #define reallocate_Character_array(array,size) \
> - (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
> + (unsigned char *) reallocate_array( (void *) array, size, sizeof( 
> unsigned char ) )
>  
>  
>  /* Used to communicate between scanner and parser.  The type should really
> @@ -755,7 +754,7 @@ extern void ccl2ecl PROTO((void));
>  extern int cre8ecs PROTO((int[], int[], int));
>  
>  /* Update equivalence classes based on character class transitions. */
> -extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
> +extern void mkeccl PROTO((unsigned char[], int, int[], int[], int, int));
>  
>  /* Create equivalence class for single character. */
>  extern void mkechar PROTO((int, int[], int[]));
> @@ -834,16 +833,16 @@ extern void bubble PROTO((int [], int));
>  extern void check_char PROTO((int c));
>  
>  /* Replace upper-case letter to lower-case. */
> -extern Char clower PROTO((int));
> +extern unsigned char clower PROTO((int));
>  
>  /* Returns a dynamically allocated copy of a string. */
>  extern char *copy_string PROTO((register const char *));
>  
>  /* Returns a dynamically allocated copy of a (potentially) unsigned string. 
> */
> -extern Char *copy_unsigned_string PROTO((register Char *));
> +extern unsigned char *copy_unsigned_string PROTO((register unsigned char *));
>  
>  /* Shell sort a character array. */
> -extern void cshell PROTO((Char [], int, int));
> +extern void cshell PROTO((unsigned char[], int, int));
>  
>  /* Finish up a block of data declarations. */
>  extern void dataend PROTO((void));
> @@ -858,7 +857,7 @@ extern void flexerror PROTO((const char[
>  extern void flexfatal PROTO((const char[]));
>  
>  /* Convert a hexadecimal digit string to an integer value. */
> -extern int htoi PROTO((Char[]));
> +extern int htoi PROTO((unsigned char[]));
>  
>  /* Report an error message formatted with one integer argument. */
>  extern void lerrif PROTO((const char[], int));
> @@ -886,10 +885,10 @@ extern void mkdata PROTO((int));/* gene
>  extern int myctoi PROTO((char []));
>  
>  /* Return character corresponding to escape sequence. */
> -extern Char myesc PROTO((Char[]));
> +extern unsigned char myesc PROTO((unsigned char[]));
>  
>  /* Convert an octal digit string to an integer value. */
> -extern int otoi PROTO((Char [] ));
> +extern int otoi PROTO((unsigned char[] ));
>  
>  /* Output a