Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/yacc use bounded string op, simplify by asprintf/strdup
details: https://anonhg.NetBSD.org/src/rev/812d39d82d8e
branches: trunk
changeset: 549441:812d39d82d8e
user: itojun <itojun%NetBSD.org@localhost>
date: Mon Jul 14 11:45:18 2003 +0000
description:
use bounded string op, simplify by asprintf/strdup
diffstat:
usr.bin/yacc/main.c | 35 +++++++++++++----------------------
usr.bin/yacc/reader.c | 10 +++++-----
usr.bin/yacc/symtab.c | 9 +++------
3 files changed, 21 insertions(+), 33 deletions(-)
diffs (178 lines):
diff -r 4ce34e4d4191 -r 812d39d82d8e usr.bin/yacc/main.c
--- a/usr.bin/yacc/main.c Mon Jul 14 11:37:49 2003 +0000
+++ b/usr.bin/yacc/main.c Mon Jul 14 11:45:18 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.12 2002/01/30 20:38:50 tv Exp $ */
+/* $NetBSD: main.c,v 1.13 2003/07/14 11:45:18 itojun Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@@ -46,7 +46,7 @@
#if 0
static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93";
#else
-__RCSID("$NetBSD: main.c,v 1.12 2002/01/30 20:38:50 tv Exp $");
+__RCSID("$NetBSD: main.c,v 1.13 2003/07/14 11:45:18 itojun Exp $");
#endif
#endif /* not lint */
@@ -321,9 +321,9 @@
union_file_name = MALLOC(i);
if (union_file_name == 0) no_space();
- strcpy(action_file_name, tmpdir);
- strcpy(text_file_name, tmpdir);
- strcpy(union_file_name, tmpdir);
+ strlcpy(action_file_name, tmpdir, i);
+ strlcpy(text_file_name, tmpdir, i);
+ strlcpy(union_file_name, tmpdir, i);
if (len && tmpdir[len - 1] != '/')
{
@@ -333,9 +333,9 @@
++len;
}
- strcpy(action_file_name + len, temp_form);
- strcpy(text_file_name + len, temp_form);
- strcpy(union_file_name + len, temp_form);
+ strlcpy(action_file_name + len, temp_form, i - len);
+ strlcpy(text_file_name + len, temp_form, i - len);
+ strlcpy(union_file_name + len, temp_form, i - len);
action_file_name[len + 5] = 'a';
text_file_name[len + 5] = 't';
@@ -345,20 +345,16 @@
if (!output_file_name)
{
- output_file_name = MALLOC(len + 7);
+ asprintf(&output_file_name, "%s%s", file_prefix, OUTPUT_SUFFIX);
if (output_file_name == 0)
no_space();
- strcpy(output_file_name, file_prefix);
- strcpy(output_file_name + len, OUTPUT_SUFFIX);
}
if (rflag)
{
- code_file_name = MALLOC(len + 8);
+ asprintf(&code_file_name, "%s%s", file_prefix, CODE_SUFFIX);
if (code_file_name == 0)
no_space();
- strcpy(code_file_name, file_prefix);
- strcpy(code_file_name + len, CODE_SUFFIX);
}
else
code_file_name = output_file_name;
@@ -368,10 +364,9 @@
if (explicit_file_name)
{
char *suffix;
- defines_file_name = MALLOC(strlen(output_file_name) + 1);
+ defines_file_name = strdup(output_file_name);
if (defines_file_name == 0)
no_space();
- strcpy(defines_file_name, output_file_name);
/* does the output_file_name have a known suffix */
suffix = strrchr(output_file_name, '.');
if (suffix != 0 &&
@@ -396,21 +391,17 @@
}
else
{
- defines_file_name = MALLOC(len + 7);
+ asprintf(&defines_file_name, "%s%s", file_prefix, DEFINES_SUFFIX);
if (defines_file_name == 0)
no_space();
- strcpy(defines_file_name, file_prefix);
- strcpy(defines_file_name + len, DEFINES_SUFFIX);
}
}
if (vflag)
{
- verbose_file_name = MALLOC(len + 8);
+ asprintf(&verbose_file_name, "%s%s", file_prefix, VERBOSE_SUFFIX);
if (verbose_file_name == 0)
no_space();
- strcpy(verbose_file_name, file_prefix);
- strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
}
}
diff -r 4ce34e4d4191 -r 812d39d82d8e usr.bin/yacc/reader.c
--- a/usr.bin/yacc/reader.c Mon Jul 14 11:37:49 2003 +0000
+++ b/usr.bin/yacc/reader.c Mon Jul 14 11:45:18 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: reader.c,v 1.11 2002/01/30 20:38:50 tv Exp $ */
+/* $NetBSD: reader.c,v 1.12 2003/07/14 11:45:18 itojun Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)reader.c 5.7 (Berkeley) 1/20/91";
#else
-__RCSID("$NetBSD: reader.c,v 1.11 2002/01/30 20:38:50 tv Exp $");
+__RCSID("$NetBSD: reader.c,v 1.12 2003/07/14 11:45:18 itojun Exp $");
#endif
#endif /* not lint */
@@ -1247,7 +1247,7 @@
bucket *bp, **bpp;
assert(cache);
- sprintf(cache, "$$%d", ++gensym);
+ snprintf(cache, cache_size, "$$%d", ++gensym);
bp = make_bucket(cache);
last_symbol->next = bp;
last_symbol = bp;
@@ -1637,8 +1637,8 @@
name_pool = MALLOC(name_pool_size);
if (name_pool == 0) no_space();
- strcpy(name_pool, "$accept");
- strcpy(name_pool+8, "$end");
+ strlcpy(name_pool, "$accept", name_pool_size);
+ strlcpy(name_pool+8, "$end", name_pool_size - 8);
t = name_pool + 13;
for (bp = first_symbol; bp; bp = bp->next)
{
diff -r 4ce34e4d4191 -r 812d39d82d8e usr.bin/yacc/symtab.c
--- a/usr.bin/yacc/symtab.c Mon Jul 14 11:37:49 2003 +0000
+++ b/usr.bin/yacc/symtab.c Mon Jul 14 11:45:18 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: symtab.c,v 1.7 2002/01/30 20:38:50 tv Exp $ */
+/* $NetBSD: symtab.c,v 1.8 2003/07/14 11:45:18 itojun Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)symtab.c 5.3 (Berkeley) 6/1/90";
#else
-__RCSID("$NetBSD: symtab.c,v 1.7 2002/01/30 20:38:50 tv Exp $");
+__RCSID("$NetBSD: symtab.c,v 1.8 2003/07/14 11:45:18 itojun Exp $");
#endif
#endif /* not lint */
@@ -88,7 +88,7 @@
if (bp == 0) no_space();
bp->link = 0;
bp->next = 0;
- bp->name = MALLOC(strlen(name) + 1);
+ bp->name = strdup(name);
if (bp->name == 0) no_space();
bp->tag = 0;
bp->value = UNDEFINED;
@@ -97,9 +97,6 @@
bp-> class = UNKNOWN;
bp->assoc = TOKEN;
- if (bp->name == 0) no_space();
- strcpy(bp->name, name);
-
return (bp);
}
Home |
Main Index |
Thread Index |
Old Index