From 5d4a38a9efb9a6ed19e592fce8fcf73d1332d1b4 Mon Sep 17 00:00:00 2001 From: Sebastian Hack Date: Tue, 14 Dec 2004 13:08:06 +0000 Subject: [PATCH] Added init function to appender. This fixes ir_snprintf, since the string was not cleaned. [r4657] --- ir/ir/irprintf.c | 50 ++++++++++++++++++++++++++++++++---------------- ir/ir/irprintf.h | 1 + 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ir/ir/irprintf.c b/ir/ir/irprintf.c index 96ded1ae5..0ba4b01c0 100644 --- a/ir/ir/irprintf.c +++ b/ir/ir/irprintf.c @@ -43,7 +43,15 @@ /** - * append a char to a string buffer + * Init the string. + */ +static void str_init(void *object, size_t n) +{ + strcpy(object, ""); +} + +/** + * append a char to a string buffer. */ static void str_append_char(void *object, size_t n, char ch) { @@ -56,15 +64,23 @@ static void str_append_char(void *object, size_t n, char ch) } /** - * append a string to a string buffer + * append a string to a string buffer. */ static void str_append_str(void *object, size_t n, const char *str) { strncat(object, str, n); } + /** - * append a char to a file + * Init the file. i.e. do nothing. + */ +static void file_init(void *object, size_t n) +{ +} + +/** + * append a char to a file. */ static void file_append_char(void *object, size_t n, char ch) { @@ -72,7 +88,7 @@ static void file_append_char(void *object, size_t n, char ch) } /** - * append a string to a file + * append a string to a file. */ static void file_append_str(void *object, size_t n, const char *str) { @@ -83,6 +99,7 @@ static void file_append_str(void *object, size_t n, const char *str) * the file appender */ static const appender_t file_appender = { + file_init, file_append_char, file_append_str }; @@ -91,6 +108,7 @@ static const appender_t file_appender = { * the string buffer appender */ static const appender_t str_appender = { + str_init, str_append_char, str_append_str }; @@ -151,10 +169,19 @@ struct settings { int alternate; }; +/* Length specifiers. */ +enum { + len_char, + len_short, + len_int, + len_long, + len_long_long +}; + + #define MIN(x,y) ((x) < (y) ? (x) : (y)) #define MAX(x,y) ((x) > (y) ? (x) : (y)) - static void dump_with_settings(const appender_t *app, void *object, size_t limit, const struct settings *settings, const char *str) { @@ -181,17 +208,6 @@ static void dump_with_settings(const appender_t *app, void *object, size_t limit } - -/* Length specifiers. */ -enum { - len_char, - len_short, - len_int, - len_long, - len_long_long -}; - - /** * A small printf helper routine for ir nodes. * @param app An appender (this determines where the stuff is dumped @@ -211,6 +227,8 @@ static void ir_common_vprintf(const appender_t *app, void *object, #define DUMP_STR(s) app->append_str(object, limit, s) #define DUMP_CH(ch) app->append_char(object, limit, ch) + app->init(object, limit); + for(i = 0, n = strlen(fmt); i < n; ++i) { char ch = fmt[i]; diff --git a/ir/ir/irprintf.h b/ir/ir/irprintf.h index 7023d2a95..60464f13f 100644 --- a/ir/ir/irprintf.h +++ b/ir/ir/irprintf.h @@ -27,6 +27,7 @@ * Something that can append strings and chars to something. */ typedef struct _appender_t { + void (*init)(void *object, size_t n); void (*append_char)(void *object, size_t n, char ch); void (*append_str)(void *object, size_t n, const char *str); } appender_t; -- 2.20.1