Subject: bin/9219: indent does not recognize all C9x constant suffixes
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ginsbach@spacestar.net>
List: netbsd-bugs
Date: 01/17/2000 17:45:45
>Number:         9219
>Category:       bin
>Synopsis:       indent does not recognize all C9x constant suffixes
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 17 17:45:00 2000
>Last-Modified:
>Originator:     Brian Ginsbach
>Organization:
None
>Release:        1.4
>Environment:
N.A.

>Description:
	In PR bin/6516 I submitted a patch that is not exactly correct
	for all possible constant suffixes.  The patch below is closer
	to how this was solved by FreeBSD and OpenBSD.  It should handle
	all possible combinations of constant suffixes.  The current
	code does not handle ones like LU or LLU which according to
	C9X are valid.  It also adds additional buffer checking.

>How-To-Repeat:
	Use indent on code that uses a suffix of LU, LLU, etc.  

>Fix:
*** lexi.c.orig	Mon Jan 17 18:21:03 2000
--- lexi.c	Mon Jan 17 18:53:37 2000
***************
*** 161,167 ****
  
  		if (isdigit((unsigned char)*buf_ptr) ||
  		    (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
! 			int     seendot = 0, seenexp = 0;
  			if (*buf_ptr == '0' &&
  			    (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) {
  				*e_token++ = *buf_ptr++;
--- 161,167 ----
  
  		if (isdigit((unsigned char)*buf_ptr) ||
  		    (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
! 			int     seendot = 0, seenexp = 0, seensfx = 0;
  			if (*buf_ptr == '0' &&
  			    (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) {
  				*e_token++ = *buf_ptr++;
***************
*** 173,191 ****
  			} else {
  				while (1) {
  					if (*buf_ptr == '.') {
! 						if (seendot)
  							break;
! 						else
  							seendot++;
  					}
  					CHECK_SIZE_TOKEN;
  					*e_token++ = *buf_ptr++;
! 					if (!isdigit((unsigned char)*buf_ptr)
! 					&& *buf_ptr != '.') {
! 						if ((*buf_ptr != 'E'
! 						&& *buf_ptr != 'e') || seenexp)
  							break;
! 						else {
  							seenexp++;
  							seendot++;
  							CHECK_SIZE_TOKEN;
--- 173,192 ----
  			} else {
  				while (1) {
  					if (*buf_ptr == '.') {
! 						if (seendot) {
  							break;
! 						} else {
  							seendot++;
+ 						}
  					}
  					CHECK_SIZE_TOKEN;
  					*e_token++ = *buf_ptr++;
! 					if (!isdigit((unsigned char)*buf_ptr) &&
! 					    *buf_ptr != '.') {
! 						if ((*buf_ptr != 'E' &&
! 						    *buf_ptr != 'e') || seenexp) {
  							break;
! 						} else {
  							seenexp++;
  							seendot++;
  							CHECK_SIZE_TOKEN;
***************
*** 201,220 ****
  				*e_token++ = *buf_ptr++;
  			} else {
  				/* integer constant (U, L, UL, LL, ULL) */
! 				if (*buf_ptr == 'U' || *buf_ptr == 'u')
! 					*e_token++ = *buf_ptr++;
! 				if (*buf_ptr == 'L' || *buf_ptr == 'l')
! 					*e_token++ = *buf_ptr++;
! 				if (*buf_ptr == 'L' || *buf_ptr == 'l')
! 					*e_token++ = *buf_ptr++;
  			}
! 		} else
  			while (chartype[(int) *buf_ptr] == alphanum) {	/* copy it over */
  				CHECK_SIZE_TOKEN;
  				*e_token++ = *buf_ptr++;
  				if (buf_ptr >= buf_end)
  					fill_buffer();
  			}
  		*e_token++ = '\0';
  		while (*buf_ptr == ' ' || *buf_ptr == '\t') {	/* get rid of blanks */
  			if (++buf_ptr >= buf_end)
--- 202,240 ----
  				*e_token++ = *buf_ptr++;
  			} else {
  				/* integer constant (U, L, UL, LL, ULL) */
! 				while (1) {
! 					if (!(seensfx & 1) &&
! 					    (*buf_ptr == 'U' || *buf_ptr == 'u')) {
! 						CHECK_SIZE_TOKEN;
! 						*e_token++ = *buf_ptr++;
! 						seensfx |= 1;
! 						continue;
! 					}
! 					if (!(seensfx & 2) &&
! 					    (*buf_ptr == 'L' || *buf_ptr == 'l')) {
! 						CHECK_SIZE_TOKEN;
! 						*e_token++ = *buf_ptr++;
! 						seensfx |= 2;
! 						continue;
! 					}
! 					if (!(seensfx & 4) &&
! 					    (*buf_ptr == 'L' || *buf_ptr == 'l')) {
! 						CHECK_SIZE_TOKEN;
! 						*e_token++ = *buf_ptr++;
! 						seensfx |= 4;
! 						continue;
! 					}
! 					break;
! 				}
  			}
! 		} else {
  			while (chartype[(int) *buf_ptr] == alphanum) {	/* copy it over */
  				CHECK_SIZE_TOKEN;
  				*e_token++ = *buf_ptr++;
  				if (buf_ptr >= buf_end)
  					fill_buffer();
  			}
+ 		}
  		*e_token++ = '\0';
  		while (*buf_ptr == ' ' || *buf_ptr == '\t') {	/* get rid of blanks */
  			if (++buf_ptr >= buf_end)
>Audit-Trail:
>Unformatted: