Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/lex use bounded string op
details: https://anonhg.NetBSD.org/src/rev/b7081ff4153b
branches: trunk
changeset: 549439:b7081ff4153b
user: itojun <itojun%NetBSD.org@localhost>
date: Mon Jul 14 11:36:48 2003 +0000
description:
use bounded string op
diffstat:
usr.bin/lex/gen.c | 13 +++++++------
usr.bin/lex/initscan.c | 17 ++++++++---------
usr.bin/lex/main.c | 10 +++++-----
usr.bin/lex/misc.c | 18 ++++++++++--------
usr.bin/lex/nfa.c | 13 +++++++------
usr.bin/lex/parse.y | 14 +++++++-------
usr.bin/lex/scan.l | 17 ++++++++---------
7 files changed, 52 insertions(+), 50 deletions(-)
diffs (truncated from 407 to 300 lines):
diff -r 275e85a48726 -r b7081ff4153b usr.bin/lex/gen.c
--- a/usr.bin/lex/gen.c Mon Jul 14 11:09:19 2003 +0000
+++ b/usr.bin/lex/gen.c Mon Jul 14 11:36:48 2003 +0000
@@ -26,7 +26,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $NetBSD: gen.c,v 1.15 2001/01/06 02:09:49 christos Exp $ */
+/* $NetBSD: gen.c,v 1.16 2003/07/14 11:36:48 itojun Exp $ */
#include "flexdef.h"
@@ -600,17 +600,18 @@
if ( worry_about_NULs && ! nultrans )
{
if ( useecs )
- (void) sprintf( char_map,
+ (void) snprintf(char_map, sizeof(char_map),
"(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
NUL_ec );
else
- (void) sprintf( char_map,
+ (void) snprintf(char_map, sizeof(char_map),
"(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
}
else
- strcpy( char_map, useecs ?
- "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );
+ strlcpy(char_map, useecs ?
+ "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)",
+ sizeof(char_map));
if ( worry_about_NULs && nultrans )
{
@@ -707,7 +708,7 @@
{
char NUL_ec_str[20];
- (void) sprintf( NUL_ec_str, "%d", NUL_ec );
+ (void) snprintf(NUL_ec_str, sizeof(NUL_ec_str), "%d", NUL_ec);
gen_next_compressed_state( NUL_ec_str );
do_indent();
diff -r 275e85a48726 -r b7081ff4153b usr.bin/lex/initscan.c
--- a/usr.bin/lex/initscan.c Mon Jul 14 11:09:19 2003 +0000
+++ b/usr.bin/lex/initscan.c Mon Jul 14 11:36:48 2003 +0000
@@ -2,7 +2,7 @@
/* A lexical scanner generated by flex */
/* Scanner skeleton version:
- * $NetBSD: initscan.c,v 1.14 2001/10/04 17:12:27 tv Exp $
+ * $NetBSD: initscan.c,v 1.15 2003/07/14 11:36:48 itojun Exp $
*/
#define FLEX_SCANNER
@@ -1272,7 +1272,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $NetBSD: initscan.c,v 1.14 2001/10/04 17:12:27 tv Exp $ */
+/* $NetBSD: initscan.c,v 1.15 2003/07/14 11:36:48 itojun Exp $ */
#include "flexdef.h"
#include "parse.h"
@@ -1294,7 +1294,7 @@
return CHAR;
#define RETURNNAME \
- strcpy( nmstr, yytext ); \
+ strlcpy(nmstr, yytext, sizeof(nmstr)); \
return NAME;
#define PUT_BACK_STRING(str, start) \
@@ -1676,7 +1676,7 @@
YY_RULE_SETUP
#line 138 "scan.l"
{
- strcpy( nmstr, yytext );
+ strlcpy(nmstr, yytext, sizeof(nmstr));
didadef = false;
BEGIN(PICKUPDEF);
}
@@ -1777,7 +1777,7 @@
YY_RULE_SETUP
#line 186 "scan.l"
{
- strcpy( (char *) nmdef, yytext );
+ strlcpy((char *) nmdef, yytext, sizeof(nmdef));
/* Skip trailing whitespace. */
for ( i = strlen( (char *) nmdef ) - 1;
@@ -2055,8 +2055,7 @@
YY_RULE_SETUP
#line 279 "scan.l"
{
- strcpy( nmstr, yytext + 1 );
- nmstr[strlen( nmstr ) - 1] = '\0';
+ strlcpy(nmstr, yytext + 1, sizeof(nmstr));
return NAME;
}
YY_BREAK
@@ -2266,7 +2265,7 @@
{
int cclval;
- strcpy( nmstr, yytext );
+ strlcpy(nmstr, yytext, sizeof(nmstr));
/* Check to see if we've already encountered this
* ccl.
@@ -2303,7 +2302,7 @@
{
register Char *nmdefptr;
- strcpy( nmstr, yytext + 1 );
+ strlcpy(nmstr, yytext + 1, sizeof(nmstr));
nmstr[yyleng - 2] = '\0'; /* chop trailing brace */
if ( (nmdefptr = ndlookup( nmstr )) == 0 )
diff -r 275e85a48726 -r b7081ff4153b usr.bin/lex/main.c
--- a/usr.bin/lex/main.c Mon Jul 14 11:09:19 2003 +0000
+++ b/usr.bin/lex/main.c Mon Jul 14 11:36:48 2003 +0000
@@ -32,7 +32,7 @@
All rights reserved.\n";
#endif /* not lint */
-/* $NetBSD: main.c,v 1.14 2002/01/29 10:20:34 tv Exp $ */
+/* $NetBSD: main.c,v 1.15 2003/07/14 11:36:49 itojun Exp $ */
#include "flexdef.h"
@@ -286,8 +286,8 @@
else
suffix = "c";
- sprintf( outfile_path, outfile_template,
- prefix, suffix );
+ snprintf(outfile_path, sizeof(outfile_path),
+ outfile_template, prefix, suffix);
outfilename = outfile_path;
}
@@ -1134,8 +1134,8 @@
if ( ! did_outfilename )
{
- sprintf( outfile_path, outfile_template,
- prefix, C_plus_plus ? "cc" : "c" );
+ snprintf(outfile_path, sizeof(outfile_path), outfile_template,
+ prefix, C_plus_plus ? "cc" : "c");
outfilename = outfile_path;
}
diff -r 275e85a48726 -r b7081ff4153b usr.bin/lex/misc.c
--- a/usr.bin/lex/misc.c Mon Jul 14 11:09:19 2003 +0000
+++ b/usr.bin/lex/misc.c Mon Jul 14 11:36:48 2003 +0000
@@ -26,7 +26,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $NetBSD: misc.c,v 1.11 2000/10/11 14:46:11 is Exp $ */
+/* $NetBSD: misc.c,v 1.12 2003/07/14 11:36:49 itojun Exp $ */
#include "flexdef.h"
@@ -44,7 +44,7 @@
return;
}
- sprintf( buf, "#define %s %d\n", defname, value );
+ snprintf(buf, sizeof(buf), "#define %s %d\n", defname, value);
add_action( buf );
}
@@ -70,7 +70,7 @@
reallocate_character_array( action_array, action_size );
}
- strcpy( &action_array[action_index], new_text );
+ strcpy(&action_array[action_index], new_text);
action_index += len;
}
@@ -362,7 +362,7 @@
int arg;
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
+ (void) snprintf(errmsg, sizeof(errmsg), msg, arg);
flexerror( errmsg );
}
@@ -374,7 +374,7 @@
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
+ (void) snprintf(errmsg, sizeof(errmsg), msg, arg);
flexerror( errmsg );
}
@@ -412,14 +412,16 @@
*s2 = '\0';
if ( do_infile )
- sprintf( directive, line_fmt, linenum, filename );
+ snprintf(directive, sizeof(directive), line_fmt, linenum,
+ filename);
else
{
if ( output_file == stdout )
/* Account for the line directive itself. */
++out_linenum;
- sprintf( directive, line_fmt, out_linenum, filename );
+ snprintf(directive, sizeof(directive), line_fmt, out_linenum,
+ filename);
}
/* If output_file is nil then we should put the directive in
@@ -731,7 +733,7 @@
#endif
default:
- (void) sprintf( rform, "\\%.3o",
+ (void) snprintf(rform, sizeof(rform), "\\%.3o",
(unsigned int) c );
return rform;
}
diff -r 275e85a48726 -r b7081ff4153b usr.bin/lex/nfa.c
--- a/usr.bin/lex/nfa.c Mon Jul 14 11:09:19 2003 +0000
+++ b/usr.bin/lex/nfa.c Mon Jul 14 11:36:48 2003 +0000
@@ -26,7 +26,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $NetBSD: nfa.c,v 1.10 1998/01/05 05:15:56 perry Exp $ */
+/* $NetBSD: nfa.c,v 1.11 2003/07/14 11:36:49 itojun Exp $ */
#include "flexdef.h"
@@ -213,7 +213,7 @@
if ( continued_action )
--rule_linenum[num_rules];
- sprintf( action_text, "case %d:\n", num_rules );
+ snprintf(action_text, sizeof(action_text), "case %d:\n", num_rules);
add_action( action_text );
if ( variable_trail_rule )
@@ -245,15 +245,16 @@
if ( headcnt > 0 )
{
- sprintf( action_text, "%s = %s + %d;\n",
- scanner_cp, scanner_bp, headcnt );
+ snprintf(action_text, sizeof(action_text),
+ "%s = %s + %d;\n", scanner_cp, scanner_bp,
+ headcnt);
add_action( action_text );
}
else
{
- sprintf( action_text, "%s -= %d;\n",
- scanner_cp, trailcnt );
+ snprintf(action_text, sizeof(action_text),
+ "%s -= %d;\n", scanner_cp, trailcnt);
add_action( action_text );
}
diff -r 275e85a48726 -r b7081ff4153b usr.bin/lex/parse.y
--- a/usr.bin/lex/parse.y Mon Jul 14 11:09:19 2003 +0000
+++ b/usr.bin/lex/parse.y Mon Jul 14 11:36:48 2003 +0000
@@ -33,7 +33,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
- /* $NetBSD: parse.y,v 1.10 2002/01/29 10:20:34 tv Exp $ */
+ /* $NetBSD: parse.y,v 1.11 2003/07/14 11:36:49 itojun Exp $ */
/* Some versions of bison are broken in that they use alloca() but don't
@@ -794,8 +794,8 @@
else
{
sceof[scon_stk[i]] = true;
- sprintf( action_text, "case YY_STATE_EOF(%s):\n",
- scname[scon_stk[i]] );
+ snprintf(action_text, sizeof(action_text),
+ "case YY_STATE_EOF(%s):\n", scname[scon_stk[i]]);
add_action( action_text );
}
}
@@ -819,7 +819,7 @@
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
Home |
Main Index |
Thread Index |
Old Index