From f633ade130356b3a809af194f97b4e67c202305e Mon Sep 17 00:00:00 2001 From: mrsmola Date: Mon, 12 Mar 2007 20:24:09 +0000 Subject: [PATCH] changed some variable types from gchar buf[SMALL] to GString *buf. A bug causes bygfoot to crash in file_compress_files. Bug message: In file.c/file_compress_files, we used gchar buf[SMALL]; SMALL is defined to 10000. after a lot of seasons (19 within the test), the number of files grows too big. --- src/file.c | 45 ++++++++++++++++++++++++++------------------- src/file.h | 4 ++-- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/file.c b/src/file.c index ceb508b2..e44f5c14 100644 --- a/src/file.c +++ b/src/file.c @@ -121,11 +121,11 @@ file_find_support_file (const gchar *filename, gboolea /** Execute command with 'system' and give a warning if return value is -1. @return TRUE on success, FALSE, otherwise. */ gboolean -file_my_system(const gchar *command) +file_my_system(const GString *command) { - if(system(command) != 0) + if(system(command->str) != 0) { - g_warning("file_my_system: system returned -1 when executing '%s'.", command); + g_warning("file_my_system: system returned -1 when executing '%s'.", command->str); if(!os_is_unix) { @@ -660,7 +660,7 @@ void file_compress_files(const gchar *destfile, const gchar *prefix) { gint i; - gchar buf[SMALL]; + GString *buf = g_string_new(""); gchar *basename = g_path_get_basename(prefix), *dirname = g_path_get_dirname(prefix), *zipbasename = g_path_get_basename(destfile), @@ -670,29 +670,30 @@ file_compress_files(const gchar *destfile, const gchar *prefix) chdir(dirname); if (os_is_unix) - sprintf(buf, "%s %s %s", + g_string_sprintf(buf, "%s %s %s", const_str("string_fs_compress_command"), const_str("string_fs_compress_switches"), zipbasename); else - sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S, + g_string_sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S, const_str("string_fs_compress_command"), const_str("string_fs_compress_switches"), zipbasename); for(i=0;ilen;i++) { - strcat(buf, " "); - strcat(buf, (gchar*)g_ptr_array_index(files, i)); + g_string_append(buf, " "); + g_string_append(buf, (gchar*)g_ptr_array_index(files, i)); } file_my_system(buf); chdir(pwd); - sprintf(buf, "%s%s%s*", dirname, G_DIR_SEPARATOR_S, basename); + g_string_sprintf(buf, "%s%s%s*", dirname, G_DIR_SEPARATOR_S, basename); file_remove_files(buf); + g_string_free(buf, TRUE); free_gchar_array(&files); g_free(basename); @@ -705,7 +706,7 @@ file_compress_files(const gchar *destfile, const gchar *prefix) void file_decompress(const gchar *filename) { - gchar buf[SMALL]; + GString *buf = g_string_new(""); gchar *dirname = g_path_get_dirname(filename), *basename = g_path_get_basename(filename), *pwd = g_get_current_dir(); @@ -713,18 +714,20 @@ file_decompress(const gchar *filename) chdir(dirname); if (os_is_unix) - sprintf(buf, "%s %s %s", + g_string_sprintf(buf, "%s %s %s", const_str("string_fs_uncompress_command"), const_str("string_fs_uncompress_switches"), basename); else - sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S, + g_string_sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S, const_str("string_fs_uncompress_command"), const_str("string_fs_uncompress_switches"), basename); file_my_system(buf); + g_string_free(buf, TRUE); + g_free(dirname); g_free(basename); @@ -735,32 +738,36 @@ file_decompress(const gchar *filename) /** Execute the appropriate remove command with 'files' as argument (can be directories or a regexp, too). */ void -file_remove_files(const gchar *files) +file_remove_files(const GString *files) { - gchar buf[SMALL]; + GString *buf = g_string_new(""); if(os_is_unix) - sprintf(buf, "%s %s", const_str("string_fs_remove_file_command"), files); + g_string_sprintf(buf, "%s %s", const_str("string_fs_remove_file_command"), files->str); else - sprintf(buf, "%s \"%s\"", const_str("string_fs_remove_file_command"), files); + g_string_sprintf(buf, "%s \"%s\"", const_str("string_fs_remove_file_command"), files->str); file_my_system(buf); + + g_string_free(buf, TRUE); } /** Execute the appropriate copy command. */ void file_copy_file(const gchar *source_file, const gchar *dest_file) { - gchar buf[SMALL]; + GString *buf = g_string_new(""); if(os_is_unix) - sprintf(buf, "%s %s %s", const_str("string_fs_copy_file_command"), + g_string_sprintf(buf, "%s %s %s", const_str("string_fs_copy_file_command"), source_file, dest_file); else - sprintf(buf, "%s \"%s\" \"%s\"", const_str("string_fs_copy_file_command"), + g_string_sprintf(buf, "%s \"%s\" \"%s\"", const_str("string_fs_copy_file_command"), source_file, dest_file); file_my_system(buf); + + g_string_free(buf, TRUE); } /** Find out where the Bygfoot directory we can write to resides diff --git a/src/file.h b/src/file.h index 83e6405a..4f22efc0 100644 --- a/src/file.h +++ b/src/file.h @@ -83,7 +83,7 @@ void file_check_home_dir_copy_files(GPtrArray **files_to_copy); gboolean -file_my_system(const gchar *command); +file_my_system(const GString *command); const gchar* file_get_first_support_dir(void); @@ -98,7 +98,7 @@ void file_decompress(const gchar *filename); void -file_remove_files(const gchar *files); +file_remove_files(const GString *files); void file_copy_file(const gchar *source_file, const gchar *dest_file);