# HG changeset patch # User ib # Date 1310033782 0 # Node ID 2c02269701bd3b6490a222bc6a8e1db27547a1c3 # Parent 9f6d46d325de407d95c151e370a4e61846fd2002 Remove macros guiSetFilename() and guiSetDF() from interface.h. Rename guiSetFilename() setdup() and guiSetDF() setddup() and define them in string.c as functions. Adjust malloc size to necessary size and check pointer returned by malloc() to prevent segmentation fault. diff -r 9f6d46d325de -r 2c02269701bd gui/interface.c --- a/gui/interface.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/interface.c Thu Jul 07 10:16:22 2011 +0000 @@ -329,7 +329,7 @@ uiSetFileName(plCurrent->path, plCurrent->name, STREAMTYPE_FILE); if (subdata) - guiSetFilename(guiInfo.Subtitlename, subdata->filename); + setdup(&guiInfo.Subtitlename, subdata->filename); guiLoadFont(); @@ -606,7 +606,7 @@ char tmp[512]; sprintf(tmp, "vcd://%d", guiInfo.Track + 1); - guiSetFilename(guiInfo.Filename, tmp); + setdup(&guiInfo.Filename, tmp); } break; #endif @@ -617,7 +617,7 @@ char tmp[512]; sprintf(tmp, "dvd://%d", guiInfo.Title); - guiSetFilename(guiInfo.Filename, tmp); + setdup(&guiInfo.Filename, tmp); } dvd_chapter = guiInfo.Chapter; @@ -632,7 +632,7 @@ if (guiInfo.Filename) filename = gstrdup(guiInfo.Filename); else if (filename) - guiSetFilename(guiInfo.Filename, filename); + setdup(&guiInfo.Filename, filename); } // video opts @@ -953,7 +953,7 @@ if (guiInfo.Playing && (next = gtkSet(gtkGetNextPlItem, 0, NULL)) && (plLastPlayed != next)) { plLastPlayed = next; - guiSetDF(guiInfo.Filename, next->path, next->name); + setddup(&guiInfo.Filename, next->path, next->name); guiInfo.StreamType = STREAMTYPE_FILE; guiInfo.FilenameChanged = guiInfo.NewPlay = 1; nfree(guiInfo.AudioFile); diff -r 9f6d46d325de -r 2c02269701bd gui/interface.h --- a/gui/interface.h Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/interface.h Thu Jul 07 10:16:22 2011 +0000 @@ -89,19 +89,6 @@ #define fsPersistant_MaxPos 5 -#define guiSetFilename(s, n) \ - { \ - free(s); \ - s = gstrdup(n); \ - } - -#define guiSetDF(s, d, n) \ - { \ - free(s); \ - s = malloc(strlen(d) + strlen(n) + 5); \ - sprintf(s, "%s/%s", d, n); \ - } - typedef struct { int x; int y; diff -r 9f6d46d325de -r 2c02269701bd gui/ui/actions.c --- a/gui/ui/actions.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/ui/actions.c Thu Jul 07 10:16:22 2011 +0000 @@ -257,9 +257,9 @@ return; if (!dir) - guiSetFilename(guiInfo.Filename, name) + setdup(&guiInfo.Filename, name); else - guiSetDF(guiInfo.Filename, dir, name) + setddup(&guiInfo.Filename, dir, name); guiInfo.StreamType = type; nfree(guiInfo.AudioFile); diff -r 9f6d46d325de -r 2c02269701bd gui/ui/gtk/fileselect.c --- a/gui/ui/gtk/fileselect.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/ui/gtk/fileselect.c Thu Jul 07 10:16:22 2011 +0000 @@ -478,7 +478,7 @@ switch ( fsType ) { case fsVideoSelector: - guiSetDF( guiInfo.Filename,fsSelectedDirectory,fsSelectedFile ); + setddup( &guiInfo.Filename,fsSelectedDirectory,fsSelectedFile ); guiInfo.StreamType=STREAMTYPE_FILE; guiInfo.FilenameChanged=1; sub_fps=0; nfree( guiInfo.AudioFile ); @@ -486,17 +486,17 @@ fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history break; case fsSubtitleSelector: - guiSetDF( guiInfo.Subtitlename,fsSelectedDirectory,fsSelectedFile ); + setddup( &guiInfo.Subtitlename,fsSelectedDirectory,fsSelectedFile ); guiLoadSubtitle( guiInfo.Subtitlename ); break; case fsOtherSelector: - guiSetDF( guiInfo.Othername,fsSelectedDirectory,fsSelectedFile ); + setddup( &guiInfo.Othername,fsSelectedDirectory,fsSelectedFile ); break; case fsAudioSelector: - guiSetDF( guiInfo.AudioFile,fsSelectedDirectory,fsSelectedFile ); + setddup( &guiInfo.AudioFile,fsSelectedDirectory,fsSelectedFile ); break; case fsFontSelector: - guiSetDF( font_name,fsSelectedDirectory,fsSelectedFile ); + setddup( &font_name,fsSelectedDirectory,fsSelectedFile ); guiLoadFont(); if ( Preferences ) gtk_entry_set_text( GTK_ENTRY( prEFontName ),font_name ); break; diff -r 9f6d46d325de -r 2c02269701bd gui/ui/gtk/playlist.c --- a/gui/ui/gtk/playlist.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/ui/gtk/playlist.c Thu Jul 07 10:16:22 2011 +0000 @@ -207,7 +207,7 @@ if ( plCurrent ) { uiSetFileName( plCurrent->path,plCurrent->name,STREAMTYPE_FILE ); -// guiSetDF( guiInfo.Filename,plCurrent->path,plCurrent->name ); +// setddup( &guiInfo.Filename,plCurrent->path,plCurrent->name ); // guiInfo.FilenameChanged=1; // guiInfo.StreamType=STREAMTYPE_FILE; } diff -r 9f6d46d325de -r 2c02269701bd gui/ui/gtk/preferences.c --- a/gui/ui/gtk/preferences.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/ui/gtk/preferences.c Thu Jul 07 10:16:22 2011 +0000 @@ -585,7 +585,7 @@ // --- 4. page - guiSetFilename( font_name,gtk_entry_get_text( GTK_ENTRY( prEFontName ) ) ); + setdup( &font_name,gtk_entry_get_text( GTK_ENTRY( prEFontName ) ) ); #ifndef CONFIG_FREETYPE gtkSet( gtkSetFontFactor,HSFontFactoradj->value,NULL ); #else @@ -636,8 +636,8 @@ if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( CBAutoSync ) ) ) { gtkAutoSync=(int)SBAutoSyncadj->value; gtkAutoSyncOn=1; } else gtkAutoSyncOn=0; - guiSetFilename( dvd_device,gtk_entry_get_text( GTK_ENTRY( prEDVDDevice ) ) ); - guiSetFilename( cdrom_device,gtk_entry_get_text( GTK_ENTRY( prECDRomDevice ) ) ); + setdup( &dvd_device,gtk_entry_get_text( GTK_ENTRY( prEDVDDevice ) ) ); + setdup( &cdrom_device,gtk_entry_get_text( GTK_ENTRY( prECDRomDevice ) ) ); case bCancel: HidePreferences(); diff -r 9f6d46d325de -r 2c02269701bd gui/ui/gtk/url.c --- a/gui/ui/gtk/url.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/ui/gtk/url.c Thu Jul 07 10:16:22 2011 +0000 @@ -102,7 +102,7 @@ item->url=gstrdup( str ); gtkSet( gtkAddURLItem,0,(void *)item ); - guiSetFilename( guiInfo.Filename,str ); guiInfo.FilenameChanged=1; + setdup( &guiInfo.Filename,str ); guiInfo.FilenameChanged=1; uiEventHandling( evPlayNetwork,0 ); } } diff -r 9f6d46d325de -r 2c02269701bd gui/util/string.c --- a/gui/util/string.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/util/string.c Thu Jul 07 10:16:22 2011 +0000 @@ -16,6 +16,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include #include #include "string.h" @@ -130,3 +132,17 @@ return strdup(str); } + +void setdup(char **old, const char *str) +{ + free(*old); + *old = gstrdup(str); +} + +void setddup(char **old, const char *dir, const char *name) +{ + free(*old); + *old = malloc(strlen(dir) + strlen(name) + 2); + if (*old) + sprintf(*old, "%s/%s", dir, name); +} diff -r 9f6d46d325de -r 2c02269701bd gui/util/string.h --- a/gui/util/string.h Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/util/string.h Thu Jul 07 10:16:22 2011 +0000 @@ -24,6 +24,8 @@ int gstrcmp(const char *a, const char *b); char *gstrdup(const char *str); int gstrncmp(const char *a, const char *b, int n); +void setddup(char **old, const char *dir, const char *name); +void setdup(char **old, const char *str); char *strlower(char *in); char *strswap(char *in, char from, char to); char *trim(char *in); diff -r 9f6d46d325de -r 2c02269701bd gui/win32/interface.c --- a/gui/win32/interface.c Thu Jul 07 09:29:15 2011 +0000 +++ b/gui/win32/interface.c Thu Jul 07 10:16:22 2011 +0000 @@ -96,6 +96,19 @@ return strdup(str); } +static void setdup (char **old, const char *str) +{ + free(*old); + *old = gstrdup(str); +} + +static void setddup (char **old, const char *dir, const char *name) +{ + free(*old); + *old = malloc(strlen(dir) + strlen(name) + 2); + if (*old) sprintf(*old, "%s/%s", dir, name); +} + /** * \brief this actually creates a new list containing only one element... */ @@ -388,9 +401,9 @@ { if(!name) return; if(!dir) - guiSetFilename(guiInfo.Filename, name) + setdup(&guiInfo.Filename, name); else - guiSetDF(guiInfo.Filename, dir, name); + setddup(&guiInfo.Filename, dir, name); guiInfo.StreamType = type; free(guiInfo.AudioFile); @@ -517,7 +530,7 @@ dvd_chapter = guiInfo.DVD.current_chapter; dvd_angle = guiInfo.DVD.current_angle; sprintf(tmp,"dvd://%d", guiInfo.Title); - guiSetFilename(guiInfo.Filename, tmp); + setdup(&guiInfo.Filename, tmp); break; } #endif