update sys/share/{dgn,lev}_lex.c

The HP C compiler for VMS issued a pair of diagnostics for both *_lex.c
files, about an expression of the form (unsigned_var <= 0) maybe not
being what was really intended, and it was right.  Changing that to
'< 1' would have suppressed the diagnostic but left the bug, which was
in code that performed a subtraction and then checked for a negative
result.  It worked in older flex versions when the variables were
signed, but got broken when they were changed to unsigned (no doubt in
respose to gcc complaining about comparing signed and unsigned in some
other spot where one of them was used).

The bug is in flex's original skeleton, so was inherited by our new
custom skeleton.  I've fixed it in the custom skeleton, which means
that sys/share/*_lex.c became out of date even though util/*_comp.l
remain unchanged.
This commit is contained in:
PatR
2015-12-08 14:52:01 -08:00
parent 7f2f15c702
commit 48f1c6711e
2 changed files with 34 additions and 38 deletions

View File

@@ -501,7 +501,7 @@ int yy_flex_debug = 0;
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
/* NetHack 3.6 dgn_comp.l $NHDT-Date: 1449385342 2015/12/06 07:02:22 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.16 $ */
/* NetHack 3.6 dgn_comp.l $NHDT-Date: 1449615114 2015/12/08 22:51:54 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.17 $ */
/* Copyright (c) 1989 by Jean-Christophe Collet */
/* Copyright (c) 1990 by M. Stephenson */
/* NetHack may be freely redistributed. See license for details. */
@@ -1147,41 +1147,37 @@ static int yy_get_next_buffer ()
*/
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
} else {
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
yy_size_t num_to_read;
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
while (num_to_read <= 0) {
/* [pr] This could probably be (b->yy_buf_size < number_to_move)
* since the allocated size is actually b->yy_buf_size + 2.
* The old code calculated num_to_read above (with same formula
* as is used below), then used (num_to_read <= 0) here, which
* got broken when num_to_read was changed to an unsigned type. */
while (b->yy_buf_size <= number_to_move + 1) {
/* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer ) {
yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
else
b->yy_buf_size *= 2;
b->yy_buf_size += b->yy_buf_size / 4;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
/* Include room in for 2 EOB chars. */
yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
} else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
if (! b->yy_ch_buf)
YY_FATAL_ERROR("fatal error - scanner input buffer overflow" );
YY_FATAL_ERROR("fatal error - scanner input buffer overflow");
(yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
number_to_move - 1;
}
num_to_read = b->yy_buf_size - number_to_move - 1;
if ( num_to_read > YY_READ_BUF_SIZE )
num_to_read = YY_READ_BUF_SIZE;
@@ -1470,6 +1466,8 @@ YY_BUFFER_STATE yy_create_buffer (file,size )
b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
if (!size)
size = YY_BUF_SIZE;
b->yy_buf_size = (yy_size_t)size;

View File

@@ -1022,7 +1022,7 @@ int yy_flex_debug = 0;
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
/* NetHack 3.6 lev_comp.l $NHDT-Date: 1449385344 2015/12/06 07:02:24 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.24 $ */
/* NetHack 3.6 lev_comp.l $NHDT-Date: 1449615116 2015/12/08 22:51:56 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.25 $ */
/* Copyright (c) 1989 by Jean-Christophe Collet */
/* NetHack may be freely redistributed. See license for details. */
@@ -2390,41 +2390,37 @@ static int yy_get_next_buffer ()
*/
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
} else {
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
yy_size_t num_to_read;
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
while (num_to_read <= 0) {
/* [pr] This could probably be (b->yy_buf_size < number_to_move)
* since the allocated size is actually b->yy_buf_size + 2.
* The old code calculated num_to_read above (with same formula
* as is used below), then used (num_to_read <= 0) here, which
* got broken when num_to_read was changed to an unsigned type. */
while (b->yy_buf_size <= number_to_move + 1) {
/* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer ) {
yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
else
b->yy_buf_size *= 2;
b->yy_buf_size += b->yy_buf_size / 4;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
/* Include room in for 2 EOB chars. */
yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
} else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
if (! b->yy_ch_buf)
YY_FATAL_ERROR("fatal error - scanner input buffer overflow" );
YY_FATAL_ERROR("fatal error - scanner input buffer overflow");
(yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
number_to_move - 1;
}
num_to_read = b->yy_buf_size - number_to_move - 1;
if ( num_to_read > YY_READ_BUF_SIZE )
num_to_read = YY_READ_BUF_SIZE;
@@ -2713,6 +2709,8 @@ YY_BUFFER_STATE yy_create_buffer (file,size )
b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
if (!size)
size = YY_BUF_SIZE;
b->yy_buf_size = (yy_size_t)size;