Mercurial > mplayer.hg
changeset 33740:2c02269701bd
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.
author | ib |
---|---|
date | Thu, 07 Jul 2011 10:16:22 +0000 |
parents | 9f6d46d325de |
children | 962dc701989d |
files | gui/interface.c gui/interface.h gui/ui/actions.c gui/ui/gtk/fileselect.c gui/ui/gtk/playlist.c gui/ui/gtk/preferences.c gui/ui/gtk/url.c gui/util/string.c gui/util/string.h gui/win32/interface.c |
diffstat | 10 files changed, 51 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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;
--- 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);
--- 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;
--- 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; }
--- 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();
--- 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 ); } }
--- 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 <stdio.h> +#include <stdlib.h> #include <string.h> #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); +}
--- 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);
--- 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