style: prefer snprintf to sprintf

* src/symtab.c (dummy_symbol_get): There's no need for the buffer to
be so big and static.
Use snprintf for safety.
This commit is contained in:
Akim Demaille
2019-02-02 10:13:22 +01:00
parent 9566232422
commit d459a5b8e6
3 changed files with 6 additions and 4 deletions

View File

@@ -17,7 +17,7 @@
# gnulib modules used by this package.
gnulib_modules='
argmatch array-list assert
argmatch array-list assert assure
bitsetv
calloc-posix close closeout config-h c-strcase
configmake

1
lib/.gitignore vendored
View File

@@ -318,3 +318,4 @@
/rename.c
/rmdir.c
/same-inode.h
/assure.h

View File

@@ -23,6 +23,7 @@
#include "system.h"
#include <assure.h>
#include <hash.h>
#include "complain.h"
@@ -865,9 +866,9 @@ dummy_symbol_get (location loc)
{
/* Incremented for each generated symbol. */
static int dummy_count = 0;
static char buf[256];
sprintf (buf, "$@%d", ++dummy_count);
char buf[32];
int len = snprintf (buf, sizeof buf, "$@%d", ++dummy_count);
assure (len < sizeof buf);
symbol *sym = symbol_get (buf, loc);
sym->content->class = nterm_sym;
sym->content->number = nvars++;