From f8a62c444f070b5e7f1ed00a2a322d01da729775 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 26 Sep 2004 23:48:31 -0400 Subject: [PATCH] made several of the buffers used non-static --- amount.cc | 11 +++++------ debug.h | 4 ++-- format.cc | 2 +- journal.cc | 4 +++- option.cc | 16 +++++++++------- quotes.cc | 1 - valexpr.cc | 3 +-- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/amount.cc b/amount.cc index 98f7cf63..1a538f40 100644 --- a/amount.cc +++ b/amount.cc @@ -671,27 +671,26 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt) void parse_quantity(std::istream& in, std::string& value) { - static char buf[256]; + char buf[256]; char c = peek_next_nonws(in); - READ_INTO(in, buf, 256, c, + READ_INTO(in, buf, 255, c, std::isdigit(c) || c == '-' || c == '.' || c == ','); value = buf; } void parse_commodity(std::istream& in, std::string& symbol) { - static char buf[256]; - + char buf[256]; char c = peek_next_nonws(in); if (c == '"') { in.get(c); - READ_INTO(in, buf, 256, c, c != '"'); + READ_INTO(in, buf, 255, c, c != '"'); if (c == '"') in.get(c); else throw amount_error("Quoted commodity symbol lacks closing quote"); } else { - READ_INTO(in, buf, 256, c, ! std::isspace(c) && ! std::isdigit(c) && + READ_INTO(in, buf, 255, c, ! std::isspace(c) && ! std::isdigit(c) && c != '-' && c != '.'); } symbol = buf; diff --git a/debug.h b/debug.h index 5c7345cf..7d3bb668 100644 --- a/debug.h +++ b/debug.h @@ -62,8 +62,8 @@ bool _debug_active(const char * const cls); #define DEBUG_PRINT_(x) DEBUG_PRINT(_debug_cls, x) #define DEBUG_PRINT_TIME(cls, x) { \ - char buf[256]; \ - std::strftime(buf, 255, "%Y/%m/%d", std::localtime(&x)); \ + char buf[16]; \ + std::strftime(buf, 15, "%Y/%m/%d", std::localtime(&x)); \ DEBUG_PRINT(cls, #x << " is " << buf); \ } diff --git a/format.cc b/format.cc index dda4b7c6..875b5177 100644 --- a/format.cc +++ b/format.cc @@ -56,7 +56,7 @@ element_t * format_t::parse_elements(const std::string& fmt) element_t * current = NULL; - static char buf[1024]; + char buf[1024]; char * q = buf; for (const char * p = fmt.c_str(); *p; p++) { diff --git a/journal.cc b/journal.cc index a949d7a4..4b33361d 100644 --- a/journal.cc +++ b/journal.cc @@ -242,9 +242,11 @@ account_t * account_t::find_account(const std::string& name, if (i != accounts.end()) return (*i).second; - static char buf[256]; + char buf[256]; std::string::size_type sep = name.find(':'); + assert(sep < 256); + const char * first, * rest; if (sep == std::string::npos) { first = name.c_str(); diff --git a/option.cc b/option.cc index d20f9de1..b34a972b 100644 --- a/option.cc +++ b/option.cc @@ -15,14 +15,15 @@ void add_option_handler(std::list& options, option_t opt; - static char buf[128]; + char buf[128]; char * p = buf; - for (const char * q = label.c_str(); *q; q++) + for (const char * q = label.c_str(); + *q && p - buf < 128; + q++) if (*q == '_') *p++ = '-'; else *p++ = *q; - assert(p < buf + 127); *p = '\0'; opt.long_opt = buf; @@ -147,15 +148,16 @@ void process_environment(std::list& options, for (char ** p = envp; *p; p++) if (std::strncmp(*p, tag_p, tag_len) == 0) { - char * q; - static char buf[128]; + char buf[128]; char * r = buf; - for (q = *p + tag_len; *q && *q != '='; q++) + char * q; + for (q = *p + tag_len; + *q && *q != '=' && r - buf < 128; + q++) if (*q == '_') *r++ += '-'; else *r++ += std::tolower(*q); - assert(r < buf + 127); *r = '\0'; if (*q == '=') diff --git a/quotes.cc b/quotes.cc index 9f43352e..84f1dffc 100644 --- a/quotes.cc +++ b/quotes.cc @@ -59,7 +59,6 @@ void quotes_by_script::operator()(commodity_t& commodity, cache_dirty = true; if (price && ! price_db.empty()) { - char buf[128]; strftime(buf, 127, "%Y/%m/%d %H:%M:%S", localtime(&now)); ofstream database(price_db.c_str(), ios_base::out | ios_base::app); database << "P " << buf << " " << commodity.symbol diff --git a/valexpr.cc b/valexpr.cc index eb2b08f9..dce9dfd9 100644 --- a/valexpr.cc +++ b/valexpr.cc @@ -430,10 +430,9 @@ inline value_expr_t * parse_value_term(const char * p) { value_expr_t * parse_value_term(std::istream& in) { - static char buf[256]; - std::auto_ptr node; + char buf[256]; char c = peek_next_nonws(in); if (std::isdigit(c)) { READ_INTO(in, buf, 255, c, std::isdigit(c));