From 88d23a2dbabf419ab4014b449be119a741aa54f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 7 May 2008 16:59:00 +0200 Subject: xine_xmalloc() deprecation: replace its use with static and non-zero size. The xine_xmalloc() function is going to be deprecated, as its behaviour is rarely needed as such, and it's thus misused. With this, almost all uses of xine_xmalloc() with static size (for instance the value returned by sizeof()) or with a size that is guaranteed not to be zero (like strlen()+1) are replaced with calls to either calloc(1, ...) or malloc(). malloc() is used whenever the allocated memory is going to be immediately overwritten, while calloc() is used in every other case, as it sets the whole memory area to zero. --HG-- extra : transplant_source : %8F%98%EC%02%1E%83%F0s%06X%83C%205Y%80%B12%CC%E1 --- src/audio_out/audio_oss_out.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/audio_out/audio_oss_out.c') diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index 40d5bcfdc..8c1e38ea7 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -729,7 +729,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da int speakers; - this = (oss_driver_t *) xine_xmalloc (sizeof (oss_driver_t)); + this = calloc(1, sizeof (oss_driver_t)); if (!this) return NULL; @@ -1170,7 +1170,7 @@ static void *init_class (xine_t *xine, void *data) { oss_class_t *this; - this = (oss_class_t *) xine_xmalloc (sizeof (oss_class_t)); + this = calloc(1, sizeof (oss_class_t)); if (!this) return NULL; -- cgit v1.2.3 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/audio_out/audio_oss_out.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/audio_out/audio_oss_out.c') diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index 8c1e38ea7..22dc4284c 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -666,7 +666,7 @@ static int probe_audio_devices(oss_driver_t *this) { int base_num, i; int audio_fd, rate; int best_rate; - char devname[30]; + char *devname[30]; strcpy(this->audio_dev, "auto"); @@ -1040,20 +1040,17 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da if ((parse = strstr(mixer_name, "dsp"))) { parse[0] = '\0'; parse += 3; - this->mixer.name = (char *)malloc(strlen(mixer_name) + sizeof("mixer") + 2); if (devname_val == 0) - sprintf(this->mixer.name, "%smixer%s", mixer_name, parse); + asprintf(&(this->mixer.name), "%smixer%s", mixer_name, parse); else { if (mixer_num == -1) - sprintf(this->mixer.name, "%smixer", mixer_name); + asprintf(&(this->mixer.name), "%smixer", mixer_name); else - sprintf(this->mixer.name, "%smixer%d", mixer_name, mixer_num); + asprintf(&(this->mixer.name), "%smixer%d", mixer_name, mixer_num); } } else { - this->mixer.name = (char *)malloc(1); - this->mixer.name[0] = '\0'; + _x_abort(); } - _x_assert(this->mixer.name[0] != '\0'); this->mixer.fd = open(this->mixer.name, O_RDONLY); -- cgit v1.2.3 From ed72565137c93ab0385a10036d234f5f4dd1b960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 7 May 2008 20:27:54 +0200 Subject: Avoid memset() on newly allocated memory areas. If needed, use calloc() to allocate the area so that it's already reset by the time it returns. --- src/audio_out/audio_oss_out.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/audio_out/audio_oss_out.c') diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c index 22dc4284c..df29a43ea 100644 --- a/src/audio_out/audio_oss_out.c +++ b/src/audio_out/audio_oss_out.c @@ -883,9 +883,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da "audio_oss_out: ...probing output buffer size: ")); this->buffer_size = 0; - if( (buf=malloc(1024)) != NULL ) { - memset(buf,0,1024); - + if( (buf=calloc(1, 1024)) != NULL ) { do { c = write(audio_fd,buf,1024); if( c != -1 ) -- cgit v1.2.3