diff --git a/ChangeLog b/ChangeLog index 485842f61f..80be0365f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-08-08 Sven Neumann + + * plug-ins/script-fu/siod-wrapper.[ch] (siod_output_string): use + g_strdup_vprintf() instead of guessing the string length. Also + declare the function using G_GNUC_PRINTF(). + 2004-08-08 Bill Skaggs * plug-ins/ifscompose/README.ifscompose: fix out of date info, diff --git a/plug-ins/script-fu/scheme-wrapper.c b/plug-ins/script-fu/scheme-wrapper.c index 6e79c3072f..7406a7e843 100644 --- a/plug-ins/script-fu/scheme-wrapper.c +++ b/plug-ins/script-fu/scheme-wrapper.c @@ -112,31 +112,28 @@ siod_get_success_msg (void) } void -siod_output_string (FILE *fp, char *string, ...) +siod_output_string (FILE *fp, + const gchar *format, + ...) { - gint buff_len; - gchar *buff; - va_list args; + gchar *buf; + va_list args; - /* Ensure plenty of room in case string contains %-style format codes */ - buff_len = strlen (string) * 2; - buff = g_malloc (buff_len); - if (buff == NULL) - return; /* Should "No memory" be output here? */ - - va_start (args, string); - g_vsnprintf (buff, buff_len, string, args); + va_start (args, format); + buf = g_strdup_vprintf (format, args); va_end (args); if (siod_console_mode && fp == stdout) - script_fu_output_to_console (buff); + { + script_fu_output_to_console (buf); + } else - { - fprintf (fp, buff); - fflush (fp); - } + { + fprintf (fp, buf); + fflush (fp); + } - g_free (buff); + g_free (buf); } diff --git a/plug-ins/script-fu/scheme-wrapper.h b/plug-ins/script-fu/scheme-wrapper.h index a5b5a1293b..8d508c9249 100644 --- a/plug-ins/script-fu/scheme-wrapper.h +++ b/plug-ins/script-fu/scheme-wrapper.h @@ -35,7 +35,9 @@ void siod_print_welcome (void); const gchar * siod_get_error_msg (void); const gchar * siod_get_success_msg (void); -void siod_output_string (FILE *fp, char *string, ...); +void siod_output_string (FILE *fp, + const gchar *format, + ...) G_GNUC_PRINTF (2, 3); /* if the return value is 0, success. error otherwise. */ gint siod_interpret_string (const gchar *expr); diff --git a/plug-ins/script-fu/siod-wrapper.c b/plug-ins/script-fu/siod-wrapper.c index 6e79c3072f..7406a7e843 100644 --- a/plug-ins/script-fu/siod-wrapper.c +++ b/plug-ins/script-fu/siod-wrapper.c @@ -112,31 +112,28 @@ siod_get_success_msg (void) } void -siod_output_string (FILE *fp, char *string, ...) +siod_output_string (FILE *fp, + const gchar *format, + ...) { - gint buff_len; - gchar *buff; - va_list args; + gchar *buf; + va_list args; - /* Ensure plenty of room in case string contains %-style format codes */ - buff_len = strlen (string) * 2; - buff = g_malloc (buff_len); - if (buff == NULL) - return; /* Should "No memory" be output here? */ - - va_start (args, string); - g_vsnprintf (buff, buff_len, string, args); + va_start (args, format); + buf = g_strdup_vprintf (format, args); va_end (args); if (siod_console_mode && fp == stdout) - script_fu_output_to_console (buff); + { + script_fu_output_to_console (buf); + } else - { - fprintf (fp, buff); - fflush (fp); - } + { + fprintf (fp, buf); + fflush (fp); + } - g_free (buff); + g_free (buf); } diff --git a/plug-ins/script-fu/siod-wrapper.h b/plug-ins/script-fu/siod-wrapper.h index a5b5a1293b..8d508c9249 100644 --- a/plug-ins/script-fu/siod-wrapper.h +++ b/plug-ins/script-fu/siod-wrapper.h @@ -35,7 +35,9 @@ void siod_print_welcome (void); const gchar * siod_get_error_msg (void); const gchar * siod_get_success_msg (void); -void siod_output_string (FILE *fp, char *string, ...); +void siod_output_string (FILE *fp, + const gchar *format, + ...) G_GNUC_PRINTF (2, 3); /* if the return value is 0, success. error otherwise. */ gint siod_interpret_string (const gchar *expr);