use bounded string op, simplify by asprintf/strdup
This commit is contained in:
parent
0e0aa0868c
commit
01a5c755ee
@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1989 The Regents of the University of California
|
||||
#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 @@ create_file_names()
|
||||
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 @@ create_file_names()
|
||||
++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 @@ create_file_names()
|
||||
|
||||
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 @@ create_file_names()
|
||||
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 @@ create_file_names()
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 @@ insert_empty_rule()
|
||||
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 @@ pack_names()
|
||||
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)
|
||||
{
|
||||
|
@ -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 @@ char *name;
|
||||
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 @@ char *name;
|
||||
bp-> class = UNKNOWN;
|
||||
bp->assoc = TOKEN;
|
||||
|
||||
if (bp->name == 0) no_space();
|
||||
strcpy(bp->name, name);
|
||||
|
||||
return (bp);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user