bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/6] style: prefer snprintf to sprintf


From: Akim Demaille
Subject: [PATCH 4/6] style: prefer snprintf to sprintf
Date: Sat, 2 Feb 2019 18:13:05 +0100

* src/symtab.c (dummy_symbol_get): There's no need for the buffer to
be so big and static.
Use snprintf for safety.
---
 src/symtab.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/symtab.c b/src/symtab.c
index 0941d2b5..f3791c69 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -865,9 +865,9 @@ dummy_symbol_get (location loc)
 {
   /* Incremented for each generated symbol.  */
   static int dummy_count = 0;
-  static char buf[256];
-
-  sprintf (buf, "address@hidden", ++dummy_count);
+  char buf[32];
+  int len = snprintf (buf, sizeof buf, "address@hidden", ++dummy_count);
+  assert (len < sizeof buf);
   symbol *sym = symbol_get (buf, loc);
   sym->content->class = nterm_sym;
   sym->content->number = nvars++;
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]