From a1101296aa6f1c0ed42f4a49ec1da63b7f76a78f Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 26 Mar 2014 14:49:48 +0900 Subject: [PATCH] refactor pic_gensym --- src/symbol.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/symbol.c b/src/symbol.c index 4501e3af..aa57d655 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -40,13 +40,13 @@ pic_intern_cstr(pic_state *pic, const char *str) pic_sym pic_gensym(pic_state *pic, pic_sym base) { - int id; + int uid = pic->uniq_sym_cnt++, len; char *str; pic_sym uniq; - id = ++pic->uniq_sym_cnt; - str = (char *)pic_alloc(pic, strlen(pic_symbol_name(pic, base)) + (int)log10(id) + 3); - sprintf(str, "%s@%d", pic_symbol_name(pic, base), id); + len = snprintf(NULL, 0, "%s@%d", pic_symbol_name(pic, base), uid); + str = pic_alloc(pic, len + 1); + sprintf(str, "%s@%d", pic_symbol_name(pic, base), uid); /* don't put the symbol to pic->syms to keep it uninterned */ uniq = pic->sym_cnt++;