From c3744b6736ce45c1c700b7f026fb0acfb0069a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 7 May 2008 17:49:47 +0200 Subject: Use asprintf() rather than malloc() + sprintf(). Using asprintf() instead of malloc() + sprintf() reduces the lines of code in xine-lib (moving the allocation to the C library or asprintf replacement), makes it safer to access the string and can also improve performance whenever the value returned by a function was used as parameter, as before it had to run the function twice in almost every case (once for strlen(), once for sprintf()). --- src/xine-engine/load_plugins.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/xine-engine/load_plugins.c') diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index fce31baca..9815b26c1 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -1072,15 +1072,13 @@ static void save_catalog (xine_t *this) { char *cachefile, *dirfile; const char *relname = CACHE_CATALOG_FILE; const char *dirname = CACHE_CATALOG_DIR; + + const char *const homedir = xine_get_homedir(); - cachefile = (char *) malloc(strlen(xine_get_homedir()) + - strlen(relname) + 2); - sprintf(cachefile, "%s/%s", xine_get_homedir(), relname); + asprintf(&cachefile, "%s/%s", homedir, relname); /* make sure homedir (~/.xine) exists */ - dirfile = (char *) malloc(strlen(xine_get_homedir()) + - strlen(dirname) + 2); - sprintf(dirfile, "%s/%s", xine_get_homedir(), dirname); + asprintf(&dirfile, "%s/%s", homedir, dirname); mkdir (dirfile, 0755); free (dirfile); @@ -1107,9 +1105,7 @@ static void load_cached_catalog (xine_t *this) { char *cachefile; const char *relname = CACHE_CATALOG_FILE; - cachefile = (char *) malloc(strlen(xine_get_homedir()) + - strlen(relname) + 2); - sprintf(cachefile, "%s/%s", xine_get_homedir(), relname); + asprintf(&cachefile, "%s/%s", xine_get_homedir(), relname); if( (fp = fopen(cachefile,"r")) != NULL ) { load_plugin_list (fp, this->plugin_catalog->cache_list); -- cgit v1.2.3