summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio_out/audio_oss_out.c17
-rw-r--r--src/combined/combined_wavpack.h3
-rw-r--r--src/combined/ffmpeg/ff_audio_decoder.c8
-rw-r--r--src/demuxers/asfheader.c9
-rw-r--r--src/demuxers/demux_4xm.c2
-rw-r--r--src/demuxers/demux_aiff.c2
-rw-r--r--src/demuxers/demux_avi.c10
-rw-r--r--src/demuxers/demux_film.c8
-rw-r--r--src/demuxers/demux_iff.c6
-rw-r--r--src/demuxers/demux_mpeg_pes.c5
-rw-r--r--src/demuxers/demux_ogg.c2
-rw-r--r--src/demuxers/demux_qt.c3
-rw-r--r--src/demuxers/demux_real.c2
-rw-r--r--src/demuxers/demux_realaudio.c2
-rw-r--r--src/demuxers/demux_slave.c6
-rw-r--r--src/demuxers/demux_str.c4
-rw-r--r--src/demuxers/demux_ts.c6
-rw-r--r--src/demuxers/demux_wav.c2
-rw-r--r--src/demuxers/demux_wc3movie.c4
-rw-r--r--src/dxr3/video_out_dxr3.c10
-rw-r--r--src/input/http_helper.c3
-rw-r--r--src/input/input_cdda.c14
-rw-r--r--src/input/input_dvb.c33
-rw-r--r--src/input/input_dvd.c12
-rw-r--r--src/input/input_file.c30
-rw-r--r--src/input/input_http.c35
-rw-r--r--src/input/input_plugin.h83
-rw-r--r--src/input/input_rtsp.c3
-rw-r--r--src/input/input_smb.c30
-rw-r--r--src/input/input_v4l.c129
-rw-r--r--src/input/input_vcd.c59
-rw-r--r--src/input/librtsp/rtsp.c58
-rw-r--r--src/input/pnm.c17
-rw-r--r--src/input/vcd/xineplug_inp_vcd.c4
-rw-r--r--src/libmusepack/xine_musepack_decoder.c2
-rw-r--r--src/libreal/xine_real_audio_decoder.c6
-rw-r--r--src/libsputext/demux_sputext.c50
-rw-r--r--src/libw32dll/wine/registry.c3
-rw-r--r--src/libw32dll/wine/win32.c3
-rw-r--r--src/libxineadec/nsf.c2
-rw-r--r--src/libxinevdec/bitplane.c20
-rw-r--r--src/libxinevdec/rgb.c2
-rw-r--r--src/post/audio/upmix_mono.c32
-rw-r--r--src/post/audio/volnorm.c5
-rw-r--r--src/post/goom/goom_core.c4
-rw-r--r--src/post/mosaico/mosaico.c7
-rw-r--r--src/post/planar/eq2.c29
-rw-r--r--src/post/planar/pp.c13
-rw-r--r--src/video_out/video_out_opengl.c8
-rw-r--r--src/video_out/video_out_xxmc.c12
-rw-r--r--src/xine-engine/alphablend.c8
-rw-r--r--src/xine-engine/alphablend.h21
-rw-r--r--src/xine-engine/buffer.h8
-rw-r--r--src/xine-engine/configfile.c3
-rw-r--r--src/xine-engine/info_helper.c7
-rw-r--r--src/xine-engine/input_cache.c2
-rw-r--r--src/xine-engine/load_plugins.c28
-rw-r--r--src/xine-engine/osd.c5
-rw-r--r--src/xine-engine/scratch.c3
-rw-r--r--src/xine-engine/xine.c11
-rw-r--r--src/xine-utils/attributes.h38
-rw-r--r--src/xine-utils/monitor.c10
-rw-r--r--src/xine-utils/utils.c20
-rw-r--r--src/xine-utils/xineutils.h2
-rw-r--r--src/xine-utils/xmllexer.c3
65 files changed, 397 insertions, 591 deletions
diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c
index 8c1e38ea7..df29a43ea 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");
@@ -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 )
@@ -1040,20 +1038,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);
diff --git a/src/combined/combined_wavpack.h b/src/combined/combined_wavpack.h
index 61a504a4f..3cfa78509 100644
--- a/src/combined/combined_wavpack.h
+++ b/src/combined/combined_wavpack.h
@@ -21,6 +21,7 @@
*/
#include "os_types.h"
+#include "attributes.h"
typedef struct {
uint32_t idcode; /* This should always be the string "wvpk" */
@@ -35,7 +36,7 @@ typedef struct {
uint32_t samples_count; /* Count of samples in the current frame */
uint32_t flags; /* Misc flags */
uint32_t decoded_crc32; /* CRC32 of the decoded data */
-} __attribute__((packed)) wvheader_t;
+} XINE_PACKED wvheader_t;
#ifdef WORDS_BIGENDIAN
static const uint32_t wvpk_signature = ('k' + ('p' << 8) + ('v' << 16) + ('w' << 24));
diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c
index de45cc1a2..4d8e440bb 100644
--- a/src/combined/ffmpeg/ff_audio_decoder.c
+++ b/src/combined/ffmpeg/ff_audio_decoder.c
@@ -249,8 +249,8 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
break; /* abort early - extradata length is bad */
this->context->extradata_size = data_len;
- this->context->extradata = xine_xmalloc(this->context->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
+ this->context->extradata = malloc(this->context->extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
xine_fast_memcpy (this->context->extradata, this->buf + extradata,
this->context->extradata_size);
break;
@@ -284,8 +284,8 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf)
(buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) {
this->context->extradata_size = buf->decoder_info[2];
- this->context->extradata = xine_xmalloc(buf->decoder_info[2] +
- FF_INPUT_BUFFER_PADDING_SIZE);
+ this->context->extradata = malloc(buf->decoder_info[2] +
+ FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(this->context->extradata, buf->decoder_info_ptr[2],
buf->decoder_info[2]);
diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c
index f95c68e41..5db25d07f 100644
--- a/src/demuxers/asfheader.c
+++ b/src/demuxers/asfheader.c
@@ -581,10 +581,9 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_
if (buffer_len < 10)
return 0;
- content = malloc(sizeof(asf_content_t));
+ content = calloc(1, sizeof(asf_content_t));
if (!content)
return 0;
- memset(content, 0, sizeof(asf_content_t));
asf_reader_init(&reader, buffer, buffer_len);
asf_reader_get_16(&reader, &title_length);
@@ -617,10 +616,9 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) {
uint32_t object_count;
uint16_t junk;
- asf_header = malloc(sizeof(asf_header_internal_t));
+ asf_header = calloc(1, sizeof(asf_header_internal_t));
if (!asf_header)
return NULL;
- memset(asf_header, 0, sizeof(asf_header_internal_t));
lprintf("parsing_asf_header\n");
if (buffer_len < 6) {
@@ -703,10 +701,9 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) {
}
if (!asf_header->pub.content) {
lprintf("no content object present\n");
- asf_header->pub.content = malloc(sizeof(asf_content_t));
+ asf_header->pub.content = calloc(1, sizeof(asf_content_t));
if (!asf_header->pub.content)
goto exit_error;
- memset(asf_header->pub.content, 0, sizeof(asf_content_t));
}
return &asf_header->pub;
diff --git a/src/demuxers/demux_4xm.c b/src/demuxers/demux_4xm.c
index a5fcd6568..c264e4421 100644
--- a/src/demuxers/demux_4xm.c
+++ b/src/demuxers/demux_4xm.c
@@ -158,7 +158,7 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) {
/* read the whole header */
header_size = _X_LE_32(&preview[4]) - 4;
- header = xine_xmalloc(header_size);
+ header = malloc(header_size);
if (!header || fourxm->input->read(fourxm->input, header, header_size) != header_size) {
free(header);
return 0;
diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c
index ae3f1ebf2..6f8953a90 100644
--- a/src/demuxers/demux_aiff.c
+++ b/src/demuxers/demux_aiff.c
@@ -85,7 +85,7 @@ typedef struct {
} demux_aiff_class_t;
/* converts IEEE 80bit extended into int, based on FFMPEG code */
-int extended_to_int(const unsigned char p[10])
+static int extended_to_int(const unsigned char p[10])
{
uint64_t m = 0;
int e, i;
diff --git a/src/demuxers/demux_avi.c b/src/demuxers/demux_avi.c
index 01efe0e53..37f74ddb1 100644
--- a/src/demuxers/demux_avi.c
+++ b/src/demuxers/demux_avi.c
@@ -790,7 +790,7 @@ static avi_t *AVI_init(demux_avi_t *this) {
if(strncasecmp(data,"hdrl",4) == 0) {
hdrl_len = n;
- hdrl_data = (unsigned char *) xine_xmalloc(n);
+ hdrl_data = (unsigned char *) malloc(n);
if(hdrl_data==0)
ERR_EXIT(AVI_ERR_NO_MEM);
if (this->input->read(this->input, hdrl_data,n) != n )
@@ -812,9 +812,8 @@ static avi_t *AVI_init(demux_avi_t *this) {
break if this is not the case */
AVI->n_idx = AVI->max_idx = n / 16;
- if (AVI->idx)
- free(AVI->idx); /* On the off chance there are multiple index chunks */
- AVI->idx = (unsigned char((*)[16])) xine_xmalloc(n);
+ free(AVI->idx); /* On the off chance there are multiple index chunks */
+ AVI->idx = (unsigned char((*)[16])) malloc(n);
if (AVI->idx == 0)
ERR_EXIT(AVI_ERR_NO_MEM);
@@ -882,7 +881,6 @@ static avi_t *AVI_init(demux_avi_t *this) {
this->AVI_errno = AVI_ERR_NO_MEM;
return 0;
}
- memset((void *)a,0,sizeof(avi_audio_t));
AVI->audio[AVI->n_audio] = a;
a->audio_strn = num_stream;
@@ -922,7 +920,7 @@ static avi_t *AVI_init(demux_avi_t *this) {
if(lasttag == 1) {
/* lprintf ("size : %d\n",sizeof(AVI->bih)); */
AVI->bih = (xine_bmiheader *)
- xine_xmalloc((n < sizeof(xine_bmiheader)) ? sizeof(xine_bmiheader) : n);
+ malloc((n < sizeof(xine_bmiheader)) ? sizeof(xine_bmiheader) : n);
if(AVI->bih == NULL) {
this->AVI_errno = AVI_ERR_NO_MEM;
return 0;
diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c
index 7abbf7134..27986d9e1 100644
--- a/src/demuxers/demux_film.c
+++ b/src/demuxers/demux_film.c
@@ -151,7 +151,7 @@ static int open_film_file(demux_film_t *film) {
/* header size = header size - 16-byte FILM signature */
film_header_size = _X_BE_32(&scratch[4]) - 16;
- film_header = xine_xmalloc(film_header_size);
+ film_header = malloc(film_header_size);
if (!film_header)
return 0;
strncpy(film->version, &scratch[8], 4);
@@ -331,10 +331,8 @@ static int open_film_file(demux_film_t *film) {
/* allocate enough space in the interleave preload buffer for the
* first chunk (which will be more than enough for successive chunks) */
if (film->audio_type) {
- if (film->interleave_buffer)
- free(film->interleave_buffer);
- film->interleave_buffer =
- xine_xmalloc(film->sample_table[0].sample_size);
+ free(film->interleave_buffer);
+ film->interleave_buffer = calloc(1, film->sample_table[0].sample_size);
if (!film->interleave_buffer)
goto film_abort;
}
diff --git a/src/demuxers/demux_iff.c b/src/demuxers/demux_iff.c
index d43eebf22..1785e86d7 100644
--- a/src/demuxers/demux_iff.c
+++ b/src/demuxers/demux_iff.c
@@ -399,7 +399,7 @@ static int read_iff_chunk(demux_iff_t *this) {
case IFF_CMAP_CHUNK:
/* every color contains red, green and blue componente using 8Bit */
this->cmap_num = junk_size / PIC_SIZE_OF_COLOR_REGISTER;
- this->cmap = (ColorRegister *)xine_xmalloc(junk_size);
+ this->cmap = (ColorRegister *)malloc(junk_size);
this->video_send_palette = 1;
if (!this->cmap || this->input->read(this->input, (char *)this->cmap, junk_size) != junk_size)
return 0;
@@ -711,14 +711,14 @@ static int demux_iff_send_chunk(demux_plugin_t *this_gen) {
if (this->audio_interleave_buffer_size > 0)
{
this->audio_interleave_buffer =
- xine_xmalloc(this->audio_interleave_buffer_size);
+ calloc(1, this->audio_interleave_buffer_size);
if (!this->audio_interleave_buffer)
return this->status = DEMUX_FINISHED;
}
if (this->audio_read_buffer_size > 0)
{
this->audio_read_buffer =
- xine_xmalloc(this->audio_read_buffer_size);
+ calloc(1, this->audio_read_buffer_size);
if (!this->audio_read_buffer)
return this->status = DEMUX_FINISHED;
}
diff --git a/src/demuxers/demux_mpeg_pes.c b/src/demuxers/demux_mpeg_pes.c
index 477a071a4..32dd2cb51 100644
--- a/src/demuxers/demux_mpeg_pes.c
+++ b/src/demuxers/demux_mpeg_pes.c
@@ -274,7 +274,7 @@ static void demux_mpeg_pes_parse_pack (demux_mpeg_pes_t *this, int preview_mode)
while ((p[2] != 1) || p[0] || p[1]) {
/* resync code */
- for(n=0;n<5;n++) p[n]=p[n+1];
+ memmove(p, p+1, 5);
i = read_data(this, p+5, (off_t) 1);
if (i != 1) {
this->status = DEMUX_FINISHED;
@@ -306,8 +306,7 @@ static void demux_mpeg_pes_parse_pack (demux_mpeg_pes_t *this, int preview_mode)
p = buf->mem;
/* copy local buffer to fifo element. */
- for (n = 0; n < sizeof (buf6); n++)
- p[ n ] = buf6[ n ];
+ memcpy(p, buf6, sizeof(buf6));
if (preview_mode)
buf->decoder_flags = BUF_FLAG_PREVIEW;
diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c
index c8c39c991..e0cddfcf4 100644
--- a/src/demuxers/demux_ogg.c
+++ b/src/demuxers/demux_ogg.c
@@ -2027,7 +2027,6 @@ static demux_plugin_t *anx_open_plugin (demux_class_t *class_gen,
*/
this = calloc(1, sizeof(demux_ogg_t));
- memset (this, 0, sizeof(demux_ogg_t));
this->stream = stream;
this->input = input;
@@ -2073,7 +2072,6 @@ static demux_plugin_t *ogg_open_plugin (demux_class_t *class_gen,
*/
this = calloc(1, sizeof(demux_ogg_t));
- memset (this, 0, sizeof(demux_ogg_t));
this->stream = stream;
this->input = input;
diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c
index bb7d62082..e51344798 100644
--- a/src/demuxers/demux_qt.c
+++ b/src/demuxers/demux_qt.c
@@ -134,7 +134,7 @@ typedef unsigned int qt_atom;
#define MAX_PTS_DIFF 100000
/* network bandwidth, cribbed from src/input/input_mms.c */
-const int64_t bandwidths[]={14400,19200,28800,33600,34430,57600,
+static const int64_t bandwidths[]={14400,19200,28800,33600,34430,57600,
115200,262200,393216,524300,1544000,10485800};
/* these are things that can go wrong */
@@ -1736,7 +1736,6 @@ static qt_error build_frame_table(qt_trak *trak,
media_id_counts = calloc(trak->stsd_atoms_count, sizeof(int));
if (!media_id_counts)
return QT_NO_MEMORY;
- memset(media_id_counts, 0, trak->stsd_atoms_count * sizeof(int));
/* iterate through each start chunk in the stsc table */
for (i = 0; i < trak->sample_to_chunk_count; i++) {
diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c
index ad5daf5ea..48bf24969 100644
--- a/src/demuxers/demux_real.c
+++ b/src/demuxers/demux_real.c
@@ -440,7 +440,7 @@ static void real_parse_headers (demux_real_t *this) {
case CONT_TAG:
chunk_size -= PREAMBLE_SIZE;
- chunk_buffer = xine_xmalloc(chunk_size);
+ chunk_buffer = malloc(chunk_size);
if (this->input->read(this->input, chunk_buffer, chunk_size) !=
chunk_size) {
free (chunk_buffer);
diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c
index e34fe0857..bc132adae 100644
--- a/src/demuxers/demux_realaudio.c
+++ b/src/demuxers/demux_realaudio.c
@@ -110,7 +110,7 @@ static int open_ra_file(demux_ra_t *this) {
}
/* allocate for and read header data */
- this->header = xine_xmalloc(this->header_size);
+ this->header = malloc(this->header_size);
if (!this->header || _x_demux_read_header(this->input, this->header, this->header_size) != this->header_size) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_realaudio: unable to read header\n");
diff --git a/src/demuxers/demux_slave.c b/src/demuxers/demux_slave.c
index c2d427d8c..28a89a973 100644
--- a/src/demuxers/demux_slave.c
+++ b/src/demuxers/demux_slave.c
@@ -186,10 +186,8 @@ static int demux_slave_next (demux_slave_t *this) {
buf->decoder_flags = decoder_flags;
/* set decoder info */
- for( i = 0; i < BUF_NUM_DEC_INFO; i++ ) {
- buf->decoder_info[i] = this->decoder_info[i];
- buf->decoder_info_ptr[i] = this->decoder_info_ptr[i];
- }
+ memcpy(buf->decoder_info, this->decoder_info, sizeof(this->decoder_info));
+ memcpy(buf->decoder_info_ptr, this->decoder_info_ptr, sizeof(this->decoder_info));
memset(this->decoder_info, 0, sizeof(this->decoder_info));
memset(this->decoder_info_ptr, 0, sizeof(this->decoder_info_ptr));
diff --git a/src/demuxers/demux_str.c b/src/demuxers/demux_str.c
index 97e025504..1e750f183 100644
--- a/src/demuxers/demux_str.c
+++ b/src/demuxers/demux_str.c
@@ -188,9 +188,7 @@ static int open_str_file(demux_str_t *this) {
unsigned char check_bytes[STR_CHECK_BYTES];
int local_offset, sector, channel;
- for (channel = 0; channel < STR_MAX_CHANNELS; channel++) {
- this->channel_type[channel] = 0;
- }
+ memset(this->channel_type, 0, sizeof(this->channel_type));
this->input->seek(this->input, 0, SEEK_SET);
if (this->input->read(this->input, check_bytes, STR_CHECK_BYTES) !=
diff --git a/src/demuxers/demux_ts.c b/src/demuxers/demux_ts.c
index c3b1c2bad..6d854e4c3 100644
--- a/src/demuxers/demux_ts.c
+++ b/src/demuxers/demux_ts.c
@@ -2278,12 +2278,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen,
this->status = DEMUX_FINISHED;
-#ifdef TS_READ_STATS
- for (i=0; i<=NPKT_PER_READ; i++) {
- this->rstat[i] = 0;
- }
-#endif
-
/* DVBSUB */
this->spu_pid = INVALID_PID;
this->spu_langs_count = 0;
diff --git a/src/demuxers/demux_wav.c b/src/demuxers/demux_wav.c
index b8d3a8229..4a1cc78ec 100644
--- a/src/demuxers/demux_wav.c
+++ b/src/demuxers/demux_wav.c
@@ -126,7 +126,7 @@ static int open_wav_file(demux_wav_t *this) {
return 0;
this->input->seek(this->input, wave_pos, SEEK_SET);
- this->wave = xine_xmalloc( this->wave_size );
+ this->wave = malloc( this->wave_size );
if (!this->wave || this->input->read(this->input, (void *)this->wave, this->wave_size) !=
this->wave_size) {
diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c
index e84dab9c6..64ae431fb 100644
--- a/src/demuxers/demux_wc3movie.c
+++ b/src/demuxers/demux_wc3movie.c
@@ -102,7 +102,7 @@ typedef struct {
} demux_mve_class_t;
/* bizarre palette lookup table */
-const unsigned char wc3_pal_lookup[] = {
+static const unsigned char wc3_pal_lookup[] = {
0x00, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0E, 0x10, 0x12, 0x13, 0x15, 0x16,
0x18, 0x19, 0x1A,
0x1C, 0x1D, 0x1F, 0x20, 0x21, 0x23, 0x24, 0x25, 0x27, 0x28, 0x29, 0x2A, 0x2C,
@@ -380,8 +380,6 @@ static int open_mve_file(demux_mve_t *this) {
/* allocate space for the shot offset index and set offsets to 0 */
this->shot_offsets = calloc(this->number_of_shots, sizeof(off_t));
this->current_shot = 0;
- for (i = 0; i < this->number_of_shots; i++)
- this->shot_offsets[i] = 0;
/* skip the SOND chunk */
this->input->seek(this->input, 12, SEEK_CUR);
diff --git a/src/dxr3/video_out_dxr3.c b/src/dxr3/video_out_dxr3.c
index 482d094b9..3e7c9ab08 100644
--- a/src/dxr3/video_out_dxr3.c
+++ b/src/dxr3/video_out_dxr3.c
@@ -1334,7 +1334,7 @@ static int lookup_parameter(struct lut_entry *lut, char *name,
static int dxr3_overlay_read_state(dxr3_overlay_t *this)
{
char *loc;
- char fname[256], tmp[128], line[256];
+ char *fname, line[256];
FILE *fp;
struct lut_entry lut[] = {
{"xoffset", TYPE_INT, &this->xoffset},
@@ -1359,18 +1359,16 @@ static int dxr3_overlay_read_state(dxr3_overlay_t *this)
* (used by .overlay/res file) */
setlocale(LC_NUMERIC, "C");
- snprintf(tmp, sizeof(tmp), "/res_%dx%dx%d",
+ asprintf(&fname, "%s/.overlay/res_%dx%dx%d", getenv("HOME"),
this->screen_xres, this->screen_yres, this->screen_depth);
- strncpy(fname, getenv("HOME"), sizeof(fname) - strlen(tmp) - sizeof("/.overlay"));
- fname[sizeof(fname) - strlen(tmp) - sizeof("/.overlay")] = '\0';
- strcat(fname, "/.overlay");
- strcat(fname, tmp);
llprintf(LOG_OVR, "attempting to open %s\n", fname);
if (!(fp = fopen(fname, "r"))) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
_("video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n"));
+ free(fname);
return -1;
}
+ free(fname);
while (!feof(fp)) {
if (!fgets(line, 256, fp))
diff --git a/src/input/http_helper.c b/src/input/http_helper.c
index 4883763b0..279d3ff05 100644
--- a/src/input/http_helper.c
+++ b/src/input/http_helper.c
@@ -240,8 +240,7 @@ char *_x_canonicalise_url (const char *base, const char *url) {
++cut;
}
base_length = cut ? (size_t)(cut - base) : strlen (base);
- ret = malloc (base_length + strlen (url) + 1);
- sprintf (ret, "%.*s%s", (int)base_length, base, url);
+ asprintf (&ret, "%.*s%s", (int)base_length, base, url);
return ret;
}
diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c
index 30b9b49e1..047916a07 100644
--- a/src/input/input_cdda.c
+++ b/src/input/input_cdda.c
@@ -1721,12 +1721,11 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) {
/* Send query command */
memset(&buffer, 0, sizeof(buffer));
- sprintf(buffer, "cddb query %08lx %d ", this->cddb.disc_id, this->cddb.num_tracks);
+ size_t size = sprintf(buffer, "cddb query %08lx %d ", this->cddb.disc_id, this->cddb.num_tracks);
for (i = 0; i < this->cddb.num_tracks; i++) {
- int size = strlen(buffer);
- snprintf(buffer + size, sizeof(buffer) - size, "%d ", this->cddb.track[i].start);
+ size += snprintf(buffer + size, sizeof(buffer) - size, "%d ", this->cddb.track[i].start);
}
- snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%d\n", this->cddb.disc_length);
+ snprintf(buffer + strlen(buffer), sizeof(buffer) - size, "%d\n", this->cddb.disc_length);
if ((err = _cdda_cddb_send_command(this, buffer)) <= 0) {
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
"input_cdda: error while sending cddb query command.\n");
@@ -2514,7 +2513,6 @@ static char ** cdda_class_get_autoplay_list (input_class_t *this_gen,
cdda_input_class_t *this = (cdda_input_class_t *) this_gen;
cdda_input_plugin_t *ip = this->ip;
cdrom_toc *toc;
- char trackmrl[20];
int fd, i, err = -1;
int num_tracks;
@@ -2580,10 +2578,8 @@ static char ** cdda_class_get_autoplay_list (input_class_t *this_gen,
num_tracks = toc->last_track - toc->first_track;
if (toc->ignore_last_track)
num_tracks--;
- for ( i = 0; i <= num_tracks; i++ ) {
- sprintf(trackmrl,"cdda:/%d",i+toc->first_track);
- this->autoplaylist[i] = strdup(trackmrl);
- }
+ for ( i = 0; i <= num_tracks; i++ )
+ asprintf(&this->autoplaylist[i],"cdda:/%d",i+toc->first_track);
*num_files = toc->last_track - toc->first_track + 1;
diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c
index 0ec81026b..669cd1e14 100644
--- a/src/input/input_dvb.c
+++ b/src/input/input_dvb.c
@@ -66,14 +66,14 @@
* OSD - this will allow for filtering/searching of epg data - useful for automatic recording :)
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
/* pthread.h must be included first so rest of the headers are imported
thread safely (on some systems). */
#include <pthread.h>
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -587,8 +587,7 @@ static tuner_t *tuner_init(xine_t * xine, int adapter)
xprintf(this->xine, XINE_VERBOSITY_DEBUG, "tuner_init adapter=%d\n", adapter);
this->fd_frontend = -1;
- for (x = 0; x < MAX_FILTERS; x++)
- this->fd_pidfilter[x] = 0;
+ memset(this->fd_pidfilter, 0, sizeof(this->fd_pidfilter));
this->xine = xine;
this->adapter_num = adapter;
@@ -933,8 +932,7 @@ static channel_t *load_channels(xine_t *xine, xine_stream_t *stream, int *num_ch
/* Initially there's no EPG data in the EPG structs. */
channels[num_channels].epg_count = 0;
- for (i = 0; i < MAX_EPG_ENTRIES_PER_CHANNEL; ++i)
- channels[num_channels].epg[i] = NULL;
+ memset(channels[num_channels].epg, 0, sizeof(channels[num_channels].epg));
num_channels++;
}
@@ -1839,8 +1837,7 @@ static void show_program_info(int x, int y, int max_x, int max_y, int* last_y,
/*Content type and rating, if any. */
if (strlen(epg_data->content) > 3) {
-
- snprintf(buffer, 94, "%s", epg_data->content);
+ strncpy(buffer, epg_data->content, 94-1);
prog_rating = epg_data->rating;
if (prog_rating > 0) {
@@ -1870,7 +1867,7 @@ static void show_program_info(int x, int y, int max_x, int max_y, int* last_y,
/* Print the description. */
if (epg_data->description && strlen(epg_data->description) > 0) {
renderer->set_font(osd, "sans", EPG_DESCRIPTION_FONT_SIZE);
- sprintf(buffer, "%s", epg_data->description);
+ strcpy(buffer, epg_data->description);
/* If the description is not complete (i.e., there is no comma at the end),
add "..." to the end. In my locale they often seem to send incomplete description
texts :( */
@@ -3223,21 +3220,19 @@ static char **dvb_class_get_autoplay_list(input_class_t * this_gen,
for (ch = 0, apch = !!lastchannel_enable.num_value;
ch < num_channels && ch < MAX_AUTOCHANNELS;
++ch, ++apch) {
- snprintf(foobuffer, BUFSIZE, "dvb://%s", channels[ch].name);
- free(class->autoplaylist[apch]);
- class->autoplaylist[apch] = strdup(foobuffer);
- _x_assert(class->autoplaylist[apch] != NULL);
+ free(class->autoplaylist[apch]);
+ asprintf(&(class->autoplaylist[apch]), "dvb://%s", channels[ch].name);
+ _x_assert(class->autoplaylist[apch] != NULL);
}
if (lastchannel_enable.num_value){
+ free(class->autoplaylist[0]);
if (default_channel != -1)
/* plugin has been used before - channel is valid */
- sprintf (foobuffer, "dvb://%s", channels[default_channel].name);
+ asprintf (&(class->autoplaylist[0]), "dvb://%s", channels[default_channel].name);
else
/* set a reasonable default - the first channel */
- sprintf (foobuffer, "dvb://%s", num_channels ? channels[0].name : "0");
- free(class->autoplaylist[0]);
- class->autoplaylist[0]=strdup(foobuffer);
+ asprintf (&(class->autoplaylist[0]), "dvb://%s", num_channels ? channels[0].name : "0");
}
free_channel_list(channels, num_channels);
diff --git a/src/input/input_dvd.c b/src/input/input_dvd.c
index 441a4544b..012d695ec 100644
--- a/src/input/input_dvd.c
+++ b/src/input/input_dvd.c
@@ -1313,7 +1313,7 @@ static int dvd_plugin_get_optional_data (input_plugin_t *this_gen,
if(this && this->stream && this->dvdnav) {
if(!(dvdnav_is_domain_vts(this->dvdnav))) {
- sprintf(data, "%s", "menu");
+ strcpy(data, "menu");
if (channel <= 0)
return INPUT_OPTIONAL_SUCCESS;
else
@@ -1336,7 +1336,7 @@ static int dvd_plugin_get_optional_data (input_plugin_t *this_gen,
return INPUT_OPTIONAL_SUCCESS;
} else {
if(channel == -1) {
- sprintf(data, "%s", "none");
+ strcpy(data, "none");
return INPUT_OPTIONAL_SUCCESS;
}
}
@@ -1369,10 +1369,7 @@ check_solaris_vold_device(dvd_input_class_t *this)
(volume_action = getenv("VOLUME_ACTION")) != NULL &&
strcmp(volume_action, "insert") == 0) {
- device = malloc(strlen(volume_device) + strlen(volume_name) + 2);
- if (device == NULL)
- return;
- sprintf(device, "%s/%s", volume_device, volume_name);
+ asprintf(&device, "%s/%s", volume_device, volume_name);
if (stat(device, &stb) != 0 || !S_ISCHR(stb.st_mode)) {
free(device);
return;
@@ -1820,8 +1817,7 @@ static void *init_class (xine_t *xine, void *data) {
"playing scrambled DVDs."), 20, NULL, NULL);
xine_setenv("DVDCSS_METHOD", decrypt_modes[mode], 0);
- css_cache_default = (char *)malloc(strlen(xine_get_homedir()) + 10);
- sprintf(css_cache_default, "%s/.dvdcss/", xine_get_homedir());
+ asprintf(&css_cache_default, "%s/.dvdcss/", xine_get_homedir());
css_cache = config->register_filename(config, "media.dvd.css_cache_path", css_cache_default, XINE_CONFIG_STRING_IS_DIRECTORY_NAME,
_("path to the title key cache"),
_("Since cracking the copy protection of scrambled DVDs can "
diff --git a/src/input/input_file.c b/src/input/input_file.c
index 3364ef46b..774f6b081 100644
--- a/src/input/input_file.c
+++ b/src/input/input_file.c
@@ -708,11 +708,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
}
else {
- dir_files[num_dir_files].mrl = (char *)
- xine_xmalloc(strlen(current_dir_slashed) + 1 + strlen(pdirent->d_name) + 1);
-
dir_files[num_dir_files].origin = strdup(current_dir);
- sprintf(dir_files[num_dir_files].mrl, "%s%s",
+ asprintf(&(dir_files[num_dir_files].mrl), "%s%s",
current_dir_slashed, pdirent->d_name);
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = get_file_type(fullfilename, current_dir, this->xine);
@@ -730,8 +727,9 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
"input_file: readlink() failed: %s\n", strerror(errno));
else {
- dir_files[num_dir_files].link = (char *) xine_xmalloc(linksize + 1);
- strncpy(dir_files[num_dir_files].link, linkbuf, linksize);
+ dir_files[num_dir_files].link =
+ strndup(linkbuf, linksize);
+
dir_files[num_dir_files].type |= get_file_type(dir_files[num_dir_files].link, current_dir, this->xine);
}
}
@@ -746,11 +744,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
/* if user don't want to see hidden files, ignore them */
if(this->show_hidden_files) {
- hide_files[num_hide_files].mrl = (char *)
- xine_xmalloc(strlen(current_dir_slashed) + 1 + strlen(pdirent->d_name) + 1);
-
hide_files[num_hide_files].origin = strdup(current_dir);
- sprintf(hide_files[num_hide_files].mrl, "%s%s",
+ asprintf(&(hide_files[num_hide_files].mrl), "%s%s",
current_dir_slashed, pdirent->d_name);
hide_files[num_hide_files].link = NULL;
hide_files[num_hide_files].type = get_file_type(fullfilename, current_dir, this->xine);
@@ -769,9 +764,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
"input_file: readlink() failed: %s\n", strerror(errno));
}
else {
- hide_files[num_hide_files].link = (char *)
- xine_xmalloc(linksize + 1);
- strncpy(hide_files[num_hide_files].link, linkbuf, linksize);
+ hide_files[num_hide_files].link =
+ strndup(linkbuf, linksize);
hide_files[num_hide_files].type |= get_file_type(hide_files[num_hide_files].link, current_dir, this->xine);
}
}
@@ -782,11 +776,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
} /* So a *normal* one. */
else {
- norm_files[num_norm_files].mrl = (char *)
- xine_xmalloc(strlen(current_dir_slashed) + 1 + strlen(pdirent->d_name) + 1);
-
norm_files[num_norm_files].origin = strdup(current_dir);
- sprintf(norm_files[num_norm_files].mrl, "%s%s",
+ asprintf(&(norm_files[num_norm_files].mrl), "%s%s",
current_dir_slashed, pdirent->d_name);
norm_files[num_norm_files].link = NULL;
norm_files[num_norm_files].type = get_file_type(fullfilename, current_dir, this->xine);
@@ -805,9 +796,8 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen,
"input_file: readlink() failed: %s\n", strerror(errno));
}
else {
- norm_files[num_norm_files].link = (char *)
- xine_xmalloc(linksize + 1);
- strncpy(norm_files[num_norm_files].link, linkbuf, linksize);
+ norm_files[num_norm_files].link =
+ strndup(linkbuf, linksize);
norm_files[num_norm_files].type |= get_file_type(norm_files[num_norm_files].link, current_dir, this->xine);
}
}
diff --git a/src/input/input_http.c b/src/input/input_http.c
index 93198a06e..deaaa0719 100644
--- a/src/input/input_http.c
+++ b/src/input/input_http.c
@@ -235,26 +235,16 @@ static int http_plugin_basicauth (const char *user, const char *password, char*
char *tmp;
char *sptr;
char *dptr;
- int totlen;
+ size_t count;
int enclen;
- int count;
- totlen = strlen (user) + 1;
- if(password != NULL)
- totlen += strlen (password);
-
- enclen = ((totlen + 2) / 3 ) * 4 + 1;
+ count = asprintf(&tmp, "%s:%s", user, (password != NULL) ? password : "");
+
+ enclen = ((count + 2) / 3 ) * 4 + 1;
if (len < enclen)
return -1;
-
- tmp = malloc (sizeof(char) * (totlen + 1));
- strcpy (tmp, user);
- strcat (tmp, ":");
- if (password != NULL)
- strcat (tmp, password);
-
- count = strlen(tmp);
+
sptr = tmp;
dptr = dest;
while (count >= 3) {
@@ -1025,8 +1015,7 @@ static input_plugin_t *http_class_get_instance (input_class_t *cls_gen, xine_str
this = calloc(1, sizeof(http_input_plugin_t));
if (!strncasecmp (mrl, "peercast://pls/", 15)) {
- this->mrl = xine_xmalloc (30 + strlen(mrl) - 15);
- sprintf (this->mrl, "http://127.0.0.1:7144/stream/%s", mrl+15);
+ asprintf (&this->mrl, "http://127.0.0.1:7144/stream/%s", mrl+15);
} else {
this->mrl = strdup (mrl);
}
@@ -1090,25 +1079,21 @@ static void *init_class (xine_t *xine, void *data) {
/*
* honour http_proxy envvar
*/
- if((proxy_env = getenv("http_proxy")) && (strlen(proxy_env))) {
+ if((proxy_env = getenv("http_proxy")) && *proxy_env) {
int proxy_port = DEFAULT_HTTP_PORT;
- char *http_proxy = xine_xmalloc(strlen(proxy_env) + 1);
char *p;
if(!strncmp(proxy_env, "http://", 7))
proxy_env += 7;
+
+ this->proxyhost_env = strdup(proxy_env);
- sprintf(http_proxy, "%s", proxy_env);
-
- if((p = strrchr(&http_proxy[0], ':')) && (strlen(p) > 1)) {
+ if((p = strrchr(this->proxyhost_env, ':')) && (strlen(p) > 1)) {
*p++ = '\0';
proxy_port = (int) strtol(p, &p, 10);
}
- this->proxyhost_env = strdup(http_proxy);
this->proxyport_env = proxy_port;
-
- free(http_proxy);
}
else
proxy_env = NULL; /* proxy_env can be "" */
diff --git a/src/input/input_plugin.h b/src/input/input_plugin.h
index 1d1e5cf53..4790164d5 100644
--- a/src/input/input_plugin.h
+++ b/src/input/input_plugin.h
@@ -333,65 +333,38 @@ struct input_plugin_s {
/*
* Freeing/zeroing all of entries of given mrl.
*/
-#define MRL_ZERO(m) { \
- if((m)) { \
- if((m)->origin) \
- free((m)->origin); \
- if((m)->mrl) \
- free((m)->mrl); \
- if((m)->link) \
- free((m)->link); \
- (m)->origin = NULL; \
- (m)->mrl = NULL; \
- (m)->link = NULL; \
- (m)->type = 0; \
- (m)->size = (off_t) 0; \
- } \
-}
+#define MRL_ZERO(m) { \
+ if((m)) { \
+ free((m)->origin); \
+ free((m)->mrl); \
+ free((m)->link); \
+ (m)->origin = NULL; \
+ (m)->mrl = NULL; \
+ (m)->link = NULL; \
+ (m)->type = 0; \
+ (m)->size = (off_t) 0; \
+ } \
+ }
/*
* Duplicate two mrls entries (s = source, d = destination).
*/
-#define MRL_DUPLICATE(s, d) { \
- _x_assert((s) != NULL); \
- _x_assert((d) != NULL); \
- \
- if((s)->origin) { \
- if((d)->origin) { \
- (d)->origin = (char *) realloc((d)->origin, strlen((s)->origin) + 1); \
- sprintf((d)->origin, "%s", (s)->origin); \
- } \
- else \
- (d)->origin = strdup((s)->origin); \
- } \
- else \
- (d)->origin = NULL; \
- \
- if((s)->mrl) { \
- if((d)->mrl) { \
- (d)->mrl = (char *) realloc((d)->mrl, strlen((s)->mrl) + 1); \
- sprintf((d)->mrl, "%s", (s)->mrl); \
- } \
- else \
- (d)->mrl = strdup((s)->mrl); \
- } \
- else \
- (d)->mrl = NULL; \
- \
- if((s)->link) { \
- if((d)->link) { \
- (d)->link = (char *) realloc((d)->link, strlen((s)->link) + 1); \
- sprintf((d)->link, "%s", (s)->link); \
- } \
- else \
- (d)->link = strdup((s)->link); \
- } \
- else \
- (d)->link = NULL; \
- \
- (d)->type = (s)->type; \
- (d)->size = (s)->size; \
-}
+#define MRL_DUPLICATE(s, d) { \
+ _x_assert((s) != NULL); \
+ _x_assert((d) != NULL); \
+ \
+ free((d)->origin); \
+ (d)->origin = (s)->origin ? strdup((s)->origin) : NULL; \
+ \
+ free((d)->mrl); \
+ (d)->mrl = (s)->mrl ? strdup((s)->mrl) : NULL; \
+ \
+ free((d)->link); \
+ (d)->link = (s)->link ? strdup((s)->link) : NULL; \
+ \
+ (d)->type = (s)->type; \
+ (d)->size = (s)->size; \
+ }
/*
* Duplicate two arrays of mrls (s = source, d = destination).
diff --git a/src/input/input_rtsp.c b/src/input/input_rtsp.c
index 8491d0a5d..db16c9bc6 100644
--- a/src/input/input_rtsp.c
+++ b/src/input/input_rtsp.c
@@ -254,8 +254,7 @@ static input_plugin_t *rtsp_class_get_instance (input_class_t *cls_gen, xine_str
/* since we handle only real streams yet, we can savely add
* an .rm extention to force handling by demux_real.
*/
- this->public_mrl = calloc(strlen(this->mrl)+10, sizeof (char));
- sprintf(this->public_mrl, "%s.rm", this->mrl);
+ asprintf(&this->public_mrl, "%s.rm", this->mrl);
this->nbc = nbc_init (stream);
diff --git a/src/input/input_smb.c b/src/input/input_smb.c
index c4706d9f3..dbab772c9 100644
--- a/src/input/input_smb.c
+++ b/src/input/input_smb.c
@@ -265,9 +265,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(
- strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}else if (pdirent->smbc_type == SMBC_SERVER){
@@ -275,17 +273,14 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup("smb:/");
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(strlen("smb:/") + 4);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", "smb:/", "..");
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", "smb:/", "..");
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup("smb:/");
- dir_files[num_dir_files].mrl =
- (char *) xine_xmalloc(strlen("smb:/") + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", "smb:/", pdirent->name);
+ asprintf(*(dir_files[num_dir_files].mrl), "%s/%s", "smb:/", pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
} else if (pdirent->smbc_type == SMBC_FILE_SHARE){
@@ -293,9 +288,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(
- strlen(current_path) + 3);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, "..");
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, "..");
dir_files[num_dir_files].type |= mrl_file_directory;
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
@@ -304,9 +297,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(
- strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}
@@ -314,18 +305,14 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl =
- (char *) xine_xmalloc(strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, pdirent->name);
dir_files[num_dir_files].size = pdirent->dirlen;
num_dir_files ++;
}else if (pdirent->smbc_type == SMBC_FILE){
norm_files[num_norm_files].link = NULL;
norm_files[num_norm_files].type = mrl_file | mrl_file_normal;
norm_files[num_norm_files].origin = strdup(current_path);
- norm_files[num_norm_files].mrl =
- (char *) xine_xmalloc(strlen(current_path) + 1 + strlen(pdirent->name) + 1);
- sprintf(norm_files[num_norm_files].mrl, "%s/%s", current_path, pdirent->name);
+ asprintf(&(norm_files[num_norm_files].mrl), "%s/%s", current_path, pdirent->name);
norm_files[num_norm_files].size = pdirent->dirlen;
num_norm_files ++;
}
@@ -335,8 +322,7 @@ static xine_mrl_t **smb_class_get_dir (input_class_t *this_gen,
if (num_dir_files == 0) {
dir_files[num_dir_files].link = NULL;
dir_files[num_dir_files].origin = strdup(current_path);
- dir_files[num_dir_files].mrl = (char *) xine_xmalloc(strlen(current_path) + 4);
- sprintf(dir_files[num_dir_files].mrl, "%s/%s", current_path, "..");
+ asprintf(&(dir_files[num_dir_files].mrl), "%s/%s", current_path, "..");
dir_files[num_dir_files].type = mrl_file | mrl_file_directory;
dir_files[num_dir_files].size = 0;
num_dir_files ++;
diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c
index 7bb5322b5..e010132ec 100644
--- a/src/input/input_v4l.c
+++ b/src/input/input_v4l.c
@@ -120,6 +120,10 @@ typedef struct {
int old_zoomx;
int old_zoomy;
int audio_only;
+
+ buf_element_t *frames_base;
+ void *audio_content_base;
+ void *video_content_base;
/* Audio */
buf_element_t *aud_frames;
@@ -711,23 +715,50 @@ static int search_by_channel(v4l_input_plugin_t *this, char *input_source)
return 1;
}
-static void allocate_audio_frames(v4l_input_plugin_t *this)
+static void allocate_frames(v4l_input_plugin_t *this, unsigned dovideo)
{
+ const size_t framescount = dovideo ? 2*NUM_FRAMES : NUM_FRAMES;
+
+ /* Allocate a single memory area for both audio and video frames */
+ buf_element_t *frames = this->frames_base =
+ calloc(framescount, sizeof(buf_element_t));
+ extra_info_t *infos =
+ calloc(framescount, sizeof(extra_info_t));
+
int i;
-
+
+ uint8_t *audio_content = this->audio_content_base =
+ calloc(NUM_FRAMES, this->periodsize);
+
+ /* Set up audio frames */
for (i = 0; i < NUM_FRAMES; i++) {
- buf_element_t *frame;
-
/* Audio frame */
- frame = calloc(1, sizeof(buf_element_t));
-
- frame->content = xine_xmalloc(this->periodsize);
- frame->type = BUF_AUDIO_LPCM_LE;
- frame->source = this;
- frame->free_buffer = store_aud_frame;
- frame->extra_info = calloc(1, sizeof(extra_info_t));
-
- store_aud_frame(frame);
+ frames[i].content = audio_content;
+ frames[i].type = BUF_AUDIO_LPCM_LE;
+ frames[i].source = this;
+ frames[i].free_buffer = store_aud_frame;
+ frames[i].extra_info = &infos[i];
+
+ audio_content += this->periodsize;
+ store_aud_frame(&frames[i]);
+ }
+
+ if ( dovideo ) {
+ uint8_t *video_content = this->video_content_base =
+ calloc(NUM_FRAMES, this->frame_size);
+
+ /* Set up video frames */
+ for (i = NUM_FRAMES; i < 2*NUM_FRAMES; i++) {
+ /* Video frame */
+ frames[i].content = video_content;
+ frames[i].type = this->frame_format;
+ frames[i].source = this;
+ frames[i].free_buffer = store_vid_frame;
+ frames[i].extra_info = &infos[i];
+
+ video_content += this->frame_size;
+ store_vid_frame(&frames[i]);
+ }
}
}
@@ -778,7 +809,7 @@ static int open_radio_capture_device(v4l_input_plugin_t *this)
/* Pre-allocate some frames for audio so it doesn't have to be done during
* capture */
- allocate_audio_frames(this);
+ allocate_frames(this, 0);
this->audio_only = 1;
@@ -850,7 +881,7 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
/* Pre-allocate some frames for audio and video so it doesn't have to be
* done during capture */
- allocate_audio_frames(this);
+ allocate_frames(this, 1);
/* Unmute audio off video capture device */
unmute_audio(this);
@@ -954,20 +985,6 @@ static int open_video_capture_device(v4l_input_plugin_t *this)
break;
}
- for (i = 0; i < NUM_FRAMES; i++) {
- buf_element_t *frame;
-
- frame = calloc(1, sizeof (buf_element_t));
-
- frame->content = xine_xmalloc (this->frame_size);
- frame->type = this->frame_format;
- frame->source = this;
- frame->free_buffer = store_vid_frame;
- frame->extra_info = calloc(1, sizeof(extra_info_t));
-
- store_vid_frame(frame);
- }
-
/* Strip the vbi / sync signal from the image by zooming in */
this->old_zoomx = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_X);
this->old_zoomy = xine_get_param(this->stream, XINE_PARAM_VO_ZOOM_Y);
@@ -1569,52 +1586,18 @@ static void v4l_plugin_dispose (input_plugin_t *this_gen) {
if (this->event_queue)
xine_event_dispose_queue (this->event_queue);
-
- lprintf("Freeing allocated audio frames");
- if (this->aud_frames) {
- buf_element_t *cur_frame = this->aud_frames;
-
- while (cur_frame != NULL) {
- buf_element_t *next_frame = cur_frame->next;
-#ifdef LOG
- printf(".");
-#endif
- if (cur_frame->content)
- free(cur_frame->content);
-
- if (cur_frame->extra_info)
- free(cur_frame->extra_info);
-
- free(cur_frame);
- cur_frame = next_frame;
- }
- }
-#ifdef LOG
- printf("\n");
-#endif
+ /* All the frames, both video and audio, are allocated in a single
+ memory area pointed by the frames_base pointer. The content of
+ the frames is divided in two areas, one pointed by
+ audio_content_base and the other by video_content_base. The
+ extra_info structures are all allocated in the first frame
+ data. */
+ free(this->audio_content_base);
+ free(this->video_content_base);
+ free(this->frames_base->extra_info);
+ free(this->frames_base);
-
- lprintf("Freeing allocated video frames");
- if (this->vid_frames) {
- buf_element_t *cur_frame = this->vid_frames;
-
- while (cur_frame != NULL) {
- buf_element_t *next_frame = cur_frame->next;
-#ifdef LOG
- printf(".");
-#endif
-
- if (cur_frame->content)
- free(cur_frame->content);
-
- if (cur_frame->extra_info)
- free(cur_frame->extra_info);
-
- free(cur_frame);
- cur_frame = next_frame;
- }
- }
#ifdef LOG
printf("\n");
#endif
diff --git a/src/input/input_vcd.c b/src/input/input_vcd.c
index 02c2e83ab..90f6fcc70 100644
--- a/src/input/input_vcd.c
+++ b/src/input/input_vcd.c
@@ -84,7 +84,7 @@ typedef struct {
const char *device;
- char *filelist[100];
+ char **filelist;
int mrls_allocated_entries;
xine_mrl_t **mrls;
@@ -924,6 +924,18 @@ static const char *vcd_class_get_identifier (input_class_t *this_gen) {
return "vcdo";
}
+static void vcd_filelist_dispose(vcd_input_class_t *this) {
+ if ( this->filelist == NULL ) return;
+
+ char **entry = this->filelist;
+
+ while(*(entry)) {
+ free(*(entry++));
+ }
+
+ free(this->filelist);
+}
+
static void vcd_class_dispose (input_class_t *this_gen) {
vcd_input_class_t *this = (vcd_input_class_t *) this_gen;
@@ -932,9 +944,7 @@ static void vcd_class_dispose (input_class_t *this_gen) {
config->unregister_callback(config, "media.vcd.device");
- for (i = 0; i < 100; i++)
- free (this->filelist[i]);
-
+ vcd_filelist_dispose(this);
free (this->mrls);
free (this);
}
@@ -982,11 +992,6 @@ static xine_mrl_t **vcd_class_get_dir (input_class_t *this_gen, const char *file
/* printf ("%d tracks\n", this->total_tracks); */
for (i=1; i<this->total_tracks; i++) { /* FIXME: check if track 0 contains valid data */
- char mrl[1024];
-
- memset(&mrl, 0, sizeof (mrl));
- sprintf(mrl, "vcdo:/%d",i);
-
if((i-1) >= this->mrls_allocated_entries) {
++this->mrls_allocated_entries;
/* note: 1 extra pointer for terminating NULL */
@@ -997,18 +1002,9 @@ static xine_mrl_t **vcd_class_get_dir (input_class_t *this_gen, const char *file
memset(this->mrls[(i-1)], 0, sizeof(xine_mrl_t));
}
- if(this->mrls[(i-1)]->mrl) {
- this->mrls[(i-1)]->mrl = (char *)
- realloc(this->mrls[(i-1)]->mrl, strlen(mrl) + 1);
- }
- else {
- this->mrls[(i-1)]->mrl = (char *) xine_xmalloc(strlen(mrl) + 1);
- }
-
- this->mrls[i-1]->origin = NULL;
- sprintf(this->mrls[i-1]->mrl, "%s", mrl);
- this->mrls[i-1]->link = NULL;
- this->mrls[i-1]->type = (0 | mrl_vcd);
+ asprintf(&(this->mrls[i-1]->mrl), "vcdo:/%d", i);
+
+ this->mrls[i-1]->type = mrl_vcd;
/* hack */
this->mrls[i-1]->size = vcd_plugin_get_length ((input_plugin_t *) this);
@@ -1055,20 +1051,15 @@ static char ** vcd_class_get_autoplay_list (input_class_t *this_gen, int *num_fi
fd = -1;
*num_files = this->total_tracks - 1;
-
- /* printf ("%d tracks\n", this->total_tracks); */
- for (i = 1; i < this->total_tracks; i++) { /* FIXME: check if track 0 contains valid data */
+ vcd_filelist_dispose(this);
+ this->filelist = calloc(this->total_tracks+1, sizeof(char*));
- if(this->filelist[i - 1] == NULL)
- this->filelist[i - 1] = (char *) realloc(this->filelist[i - 1], sizeof(char *) * 256);
+ /* FIXME: check if track 0 contains valid data */
+ for (i = 1; i < this->total_tracks; i++)
+ asprintf(&this->filelist[i-1], "vcdo:/%d", i);
- sprintf (this->filelist[i - 1], "vcdo:/%d",i);
- /* printf ("list[%d] : %d %s\n", i, this->filelist[i-1], this->filelist[i-1]); */
- }
-
- this->filelist[i - 1] = (char *) realloc(this->filelist[i-1], sizeof(char *));
- this->filelist[i - 1] = NULL;
+ /* printf ("%d tracks\n", this->total_tracks); */
return this->filelist;
}
@@ -1100,10 +1091,6 @@ static void *init_class (xine_t *xine, void *data) {
this->mrls = calloc(1, sizeof(xine_mrl_t*));
this->mrls_allocated_entries = 0;
- for (i = 0; i < 100; i++) {
- this->filelist[i] = calloc(256, sizeof(char));
- }
-
return this;
}
diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c
index 530ffc6cf..4e17c1e57 100644
--- a/src/input/librtsp/rtsp.c
+++ b/src/input/librtsp/rtsp.c
@@ -21,6 +21,10 @@
* *not* RFC 2326 compilant yet.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
@@ -173,9 +177,7 @@ static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
char **payload=s->scheduled;
char *buf;
- buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3);
-
- sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version);
+ asprintf(&buf,"%s %s %s",type, what, rtsp_protocol_version);
rtsp_put(s,buf);
free(buf);
if (payload)
@@ -200,8 +202,7 @@ static void rtsp_schedule_standard(rtsp_t *s) {
if (s->session) {
char *buf;
- buf = malloc(strlen(s->session)+15);
- sprintf(buf, "Session: %s", s->session);
+ asprintf(&buf, "Session: %s", s->session);
rtsp_schedule_field(s, buf);
free(buf);
}
@@ -232,38 +233,32 @@ static int rtsp_get_answers(rtsp_t *s) {
if (!answer)
return 0;
- if (!strncasecmp(answer,"Cseq:",5)) {
- sscanf(answer,"%*s %u",&answer_seq);
+ if (!strncasecmp(answer,"Cseq: ",6)) {
+ sscanf(answer+6,"%u",&answer_seq);
if (s->cseq != answer_seq) {
lprintf("warning: Cseq mismatch. got %u, assumed %u", answer_seq, s->cseq);
s->cseq=answer_seq;
}
}
- if (!strncasecmp(answer,"Server:",7)) {
- char *buf = xine_xmalloc(strlen(answer));
- sscanf(answer,"%*s %s",buf);
- if (s->server) free(s->server);
- s->server=strdup(buf);
- free(buf);
+ if (!strncasecmp(answer,"Server: ",8)) {
+ free(s->server);
+ s->server = strdup(answer + 8);
}
- if (!strncasecmp(answer,"Session:",8)) {
- char *buf = xine_xmalloc(strlen(answer));
- sscanf(answer,"%*s %s",buf);
+ if (!strncasecmp(answer,"Session: ",9)) {
+ char *tmp = answer + 9;
if (s->session) {
- if (strcmp(buf, s->session)) {
+ if (strcmp(tmp, s->session)) {
xprintf(s->stream->xine, XINE_VERBOSITY_DEBUG,
- "rtsp: warning: setting NEW session: %s\n", buf);
- free(s->session);
- s->session=strdup(buf);
+ "rtsp: warning: setting NEW session: %s\n", tmp);
+ s->session=strdup(tmp);
}
} else
{
lprintf("setting session id to: %s\n", buf);
- s->session=strdup(buf);
+ s->session=strdup(tmp);
}
- free(buf);
}
*answer_ptr=answer;
answer_ptr++;
@@ -304,8 +299,7 @@ int rtsp_request_options(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+16));
- sprintf(buf,"rtsp://%s:%i", s->host, s->port);
+ asprintf(&buf,"rtsp://%s:%i", s->host, s->port);
}
rtsp_send_request(s,"OPTIONS",buf);
free(buf);
@@ -321,8 +315,7 @@ int rtsp_request_describe(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
- sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
+ asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
}
rtsp_send_request(s,"DESCRIBE",buf);
free(buf);
@@ -345,8 +338,7 @@ int rtsp_request_setparameter(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
- sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
+ asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
}
rtsp_send_request(s,"SET_PARAMETER",buf);
free(buf);
@@ -362,8 +354,7 @@ int rtsp_request_play(rtsp_t *s, const char *what) {
buf=strdup(what);
} else
{
- buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
- sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
+ asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
}
rtsp_send_request(s,"PLAY",buf);
free(buf);
@@ -412,8 +403,7 @@ int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) {
}
/* lets make the server happy */
rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood");
- rest = malloc(sizeof(char)*17);
- sprintf(rest,"CSeq: %u", seq);
+ asprintf(&rest,"CSeq: %u", seq);
rtsp_put(s, rest);
free(rest);
rtsp_put(s, "");
@@ -486,9 +476,7 @@ rtsp_t *rtsp_connect(xine_stream_t *stream, const char *mrl, const char *user_ag
pathbegin=slash-mrl_ptr;
hostend=colon-mrl_ptr;
- s->host = malloc(sizeof(char)*hostend+1);
- strncpy(s->host, mrl_ptr, hostend);
- s->host[hostend]=0;
+ s->host = strndup(mrl_ptr, hostend);
if (pathbegin < strlen(mrl_ptr)) s->path=strdup(mrl_ptr+pathbegin+1);
if (colon != slash) {
diff --git a/src/input/pnm.c b/src/input/pnm.c
index fca2050d3..5b8aa7c42 100644
--- a/src/input/pnm.c
+++ b/src/input/pnm.c
@@ -21,6 +21,10 @@
* based upon code from joschka
*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
@@ -90,7 +94,7 @@ struct pnm_s {
/* header of rm files */
#define RM_HEADER_SIZE 0x12
-const unsigned char rm_header[]={
+static const unsigned char rm_header[]={
0x2e, 0x52, 0x4d, 0x46, /* object_id ".RMF" */
0x00, 0x00, 0x00, 0x12, /* header_size 0x12 */
0x00, 0x00, /* object_version 0x00 */
@@ -100,7 +104,7 @@ const unsigned char rm_header[]={
/* data chunk header */
#define PNM_DATA_HEADER_SIZE 18
-const unsigned char pnm_data_header[]={
+static const unsigned char pnm_data_header[]={
'D','A','T','A',
0,0,0,0, /* data chunk size */
0,0, /* object version */
@@ -627,10 +631,7 @@ static int pnm_get_stream_chunk(pnm_t *p) {
*/
n=0;
while (p->buffer[0] != 0x5a) {
- int i;
- for (i=1; i<8; i++) {
- p->buffer[i-1]=p->buffer[i];
- }
+ memmove(p->buffer, &p->buffer[1], 8);
_x_io_tcp_read (p->stream, p->s, &p->buffer[7], 1);
n++;
}
@@ -732,9 +733,7 @@ pnm_t *pnm_connect(xine_stream_t *stream, const char *mrl) {
pathbegin=slash-mrl_ptr;
hostend=colon-mrl_ptr;
- p->host = malloc(sizeof(char)*hostend+1);
- strncpy(p->host, mrl_ptr, hostend);
- p->host[hostend]=0;
+ p->host = strndup(mrl_ptr, hostend);
if (pathbegin < strlen(mrl_ptr)) p->path=strdup(mrl_ptr+pathbegin+1);
if (colon != slash) {
diff --git a/src/input/vcd/xineplug_inp_vcd.c b/src/input/vcd/xineplug_inp_vcd.c
index d024c5bff..f4f823918 100644
--- a/src/input/vcd/xineplug_inp_vcd.c
+++ b/src/input/vcd/xineplug_inp_vcd.c
@@ -272,11 +272,9 @@ vcd_add_mrl_slot(vcd_input_class_t *this, const char *mrl, off_t size,
this->mrls[*i]->type = mrl_vcd;
this->mrls[*i]->size = size * M2F2_SECTOR_SIZE;
- this->mrls[*i]->mrl = (char *) malloc(strlen(mrl) + 1);
+ this->mrls[*i]->mrl = strdup(mrl);
if (NULL==this->mrls[*i]->mrl) {
LOG_ERR("Can't malloc %zu bytes for MRL name %s", sizeof(xine_mrl_t), mrl);
- } else {
- sprintf(this->mrls[*i]->mrl, "%s", mrl);
}
(*i)++;
}
diff --git a/src/libmusepack/xine_musepack_decoder.c b/src/libmusepack/xine_musepack_decoder.c
index 39d17f574..115532e86 100644
--- a/src/libmusepack/xine_musepack_decoder.c
+++ b/src/libmusepack/xine_musepack_decoder.c
@@ -214,7 +214,7 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
this->file_size = buf->decoder_info[0];
/* Initialise the data accumulation buffer */
- this->buf = xine_xmalloc(INIT_BUFSIZE);
+ this->buf = calloc(1, INIT_BUFSIZE);
this->buf_max = INIT_BUFSIZE;
this->read = 0;
this->size = 0;
diff --git a/src/libreal/xine_real_audio_decoder.c b/src/libreal/xine_real_audio_decoder.c
index 296077b6d..7f4942cc5 100644
--- a/src/libreal/xine_real_audio_decoder.c
+++ b/src/libreal/xine_real_audio_decoder.c
@@ -310,14 +310,14 @@ static int init_codec (realdec_decoder_t *this, buf_element_t *buf) {
if (this->sps) {
this->frame_size = this->w/this->sps*this->h*this->sps;
- this->frame_buffer = xine_xmalloc (this->frame_size);
- this->frame_reordered = xine_xmalloc (this->frame_size);
+ this->frame_buffer = calloc (1, this->frame_size);
+ this->frame_reordered = calloc (1, this->frame_size);
this->frame_num_bytes = 0;
} else {
this->frame_size = this->w*this->h;
- this->frame_buffer = xine_xmalloc (this->frame_size);
+ this->frame_buffer = calloc (this->w, this->h);
this->frame_reordered = this->frame_buffer;
this->frame_num_bytes = 0;
diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c
index b159d3d7f..f7cd5af83 100644
--- a/src/libsputext/demux_sputext.c
+++ b/src/libsputext/demux_sputext.c
@@ -262,12 +262,7 @@ static char *sub_readtext(char *source, char **dest) {
p++,len++;
}
- *dest= (char *)xine_xmalloc (len+1);
- if (!(*dest))
- return ERR;
-
- strncpy(*dest, source, len);
- (*dest)[len]=0;
+ *dest = strndup(source, len);
while (*p=='\r' || *p=='\n' || *p=='|')
p++;
@@ -333,10 +328,8 @@ static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t *cu
p=q=line;
for (current->lines=1; current->lines <= SUB_MAX_TEXT; current->lines++) {
for (q=p,len=0; *p && *p!='\r' && *p!='\n' && *p!='|' && strncasecmp(p,"[br]",4); p++,len++);
- current->text[current->lines-1]=(char *)xine_xmalloc (len+1);
+ current->text[current->lines-1] = strndup(q, len);
if (!current->text[current->lines-1]) return ERR;
- strncpy (current->text[current->lines-1], q, len);
- current->text[current->lines-1][len]='\0';
if (!*p || *p=='\r' || *p=='\n') break;
if (*p=='[') while (*p++!=']');
if (*p=='|') p++;
@@ -396,10 +389,10 @@ static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *curren
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "Too many characters in a subtitle line\n");
if(temp_line[temp_index-1]=='\0' || temp_index==SUB_BUFSIZE) {
if(temp_index>1) { /* more than 1 char (including '\0') -> that is a valid one */
- current->text[i]=(char *)xine_xmalloc(temp_index);
+ /* temp_index<=SUB_BUFSIZE is always true here */
+ current->text[i] = strndup(temp_line, temp_index);
if(!current->text[i])
return ERR;
- strncpy(current->text[i],temp_line,temp_index); /* temp_index<=SUB_BUFSIZE is always true here */
i++;
temp_index=0;
} else
@@ -565,9 +558,7 @@ static subtitle_t *sub_read_line_ssa(demux_sputext_t *this,subtitle_t *current)
current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2;
while (((tmp=strstr(line2, "\\n")) != NULL) || ((tmp=strstr(line2, "\\N")) != NULL) ){
- current->text[num]=(char *)malloc(tmp-line2+1);
- strncpy (current->text[num], line2, tmp-line2);
- current->text[num][tmp-line2]='\0';
+ current->text[num] = strndup(line2, tmp-line2);
line2=tmp+2;
num++;
current->lines++;
@@ -802,26 +793,19 @@ static subtitle_t *sub_read_line_jacobsub(demux_sputext_t *this, subtitle_t *cur
++p;
}
if (isalpha(*p)||*p == '[') {
- int cont, jLength;
-
if (sscanf(p, "%s %" LINE_LEN_QUOT "[^\n\r]", directive, line1) < 2)
return ERR;
- jLength = strlen(directive);
- for (cont = 0; cont < jLength; ++cont) {
- if (isalpha(*(directive + cont)))
- *(directive + cont) = toupper(*(directive + cont));
- }
- if ((strstr(directive, "RDB") != NULL)
- || (strstr(directive, "RDC") != NULL)
- || (strstr(directive, "RLB") != NULL)
- || (strstr(directive, "RLG") != NULL)) {
+ if ((strcasestr(directive, "RDB") != NULL)
+ || (strcasestr(directive, "RDC") != NULL)
+ || (strcasestr(directive, "RLB") != NULL)
+ || (strcasestr(directive, "RLG") != NULL)) {
continue;
}
/* no alignment */
#if 0
- if (strstr(directive, "JL") != NULL) {
+ if (strcasestr(directive, "JL") != NULL) {
current->alignment = SUB_ALIGNMENT_HLEFT;
- } else if (strstr(directive, "JR") != NULL) {
+ } else if (strcasestr(directive, "JR") != NULL) {
current->alignment = SUB_ALIGNMENT_HRIGHT;
} else {
current->alignment = SUB_ALIGNMENT_HCENTER;
@@ -930,10 +914,9 @@ static subtitle_t *sub_read_line_subviewer2(demux_sputext_t *this, subtitle_t *c
len=0;
for (p=line; *p!='\n' && *p!='\r' && *p; ++p,++len);
if (len) {
- current->text[i]=(char *)malloc (len+1);
- if (!current->text[i]) return ERR;
- strncpy (current->text[i], line, len); current->text[i][len]='\0';
- ++i;
+ current->text[i] = strndup(line, len);
+ if (!current->text[i]) return ERR;
+ ++i;
} else {
break;
}
@@ -1250,9 +1233,8 @@ static int demux_sputext_next (demux_sputext_t *this_gen) {
*val++ = (this->uses_time) ? sub->end * 10 : sub->end;
str = (char *)val;
for (line = 0; line < sub->lines; line++, str+=strlen(str)+1) {
- if( strlen(sub->text[line]) > SUB_BUFSIZE )
- sub->text[line][SUB_BUFSIZE] = '\0';
- strcpy(str, sub->text[line]);
+ strncpy(str, sub->text[line], SUB_BUFSIZE-1);
+ str[SUB_BUFSIZE-1] = '\0';
}
this->stream->video_fifo->put(this->stream->video_fifo, buf);
diff --git a/src/libw32dll/wine/registry.c b/src/libw32dll/wine/registry.c
index 0f91499b3..0ccf3de9b 100644
--- a/src/libw32dll/wine/registry.c
+++ b/src/libw32dll/wine/registry.c
@@ -311,8 +311,7 @@ static void init_registry(void)
localregpathname = regpathname;
#else
#ifdef XINE_MAJOR
- localregpathname = (char *)malloc(strlen(xine_get_homedir()) + 21);
- sprintf(localregpathname, "%s/.xine/win32registry", xine_get_homedir());
+ asprintf(&localregpathname, "%s/.xine/win32registry", xine_get_homedir());
#else
// regpathname is an external pointer
//
diff --git a/src/libw32dll/wine/win32.c b/src/libw32dll/wine/win32.c
index 9b627a10a..f908f1c2e 100644
--- a/src/libw32dll/wine/win32.c
+++ b/src/libw32dll/wine/win32.c
@@ -3491,9 +3491,8 @@ static HANDLE WINAPI expCreateFileA(LPCSTR cs1,DWORD i1,DWORD i2,
if(strstr(cs1, ".qtx"))
{
int result;
- char* tmp=(char*)malloc(strlen(win32_def_path)+250);
char* x=strrchr(cs1,'\\');
- sprintf(tmp,"%s/%s",win32_def_path,x?(x+1):cs1);
+ asprintf(&tmp,"%s/%s",win32_def_path,x?(x+1):cs1);
// printf("### Open: %s -> %s\n",cs1,tmp);
result=open(tmp, O_RDONLY);
free(tmp);
diff --git a/src/libxineadec/nsf.c b/src/libxineadec/nsf.c
index 4b476d036..0c9cdbf55 100644
--- a/src/libxineadec/nsf.c
+++ b/src/libxineadec/nsf.c
@@ -90,7 +90,7 @@ static void nsf_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
this->song_number = buf->content[4];
/* allocate a buffer for the file */
this->nsf_size = _X_BE_32(&buf->content[0]);
- this->nsf_file = xine_xmalloc(this->nsf_size);
+ this->nsf_file = calloc(1, this->nsf_size);
this->nsf_index = 0;
/* peform any other required initialization */
diff --git a/src/libxinevdec/bitplane.c b/src/libxinevdec/bitplane.c
index 5cee51764..057511c29 100644
--- a/src/libxinevdec/bitplane.c
+++ b/src/libxinevdec/bitplane.c
@@ -252,7 +252,7 @@ static uint8_t *bitplane_decode_byterun1 (uint8_t *compressed,
int i = 0;
int j = 0;
- uint8_t *uncompressed = xine_xmalloc( size_uncompressed );
+ uint8_t *uncompressed = calloc(1, size_uncompressed );
while ( i < size_compressed &&
pixel_ptr < size_uncompressed ) {
@@ -1189,7 +1189,7 @@ static void bitplane_decode_data (video_decoder_t *this_gen,
if (this->buf)
free (this->buf);
this->bufsize = VIDEOBUFSIZE;
- this->buf = xine_xmalloc(this->bufsize);
+ this->buf = calloc(1, this->bufsize);
this->size = 0;
this->framenumber = 0;
@@ -1255,7 +1255,7 @@ static void bitplane_decode_data (video_decoder_t *this_gen,
case BUF_VIDEO_BITPLANE:
/* uncompressed Buffer, set decoded_buf pointer direct to input stream */
if( this->buf_uk == NULL )
- this->buf_uk = xine_xmalloc( (this->size) );
+ this->buf_uk = malloc(this->size);
xine_fast_memcpy (this->buf_uk, this->buf, this->size);
break;
case BUF_VIDEO_BITPLANE_BR1:
@@ -1294,7 +1294,7 @@ static void bitplane_decode_data (video_decoder_t *this_gen,
}
}
if( this->buf_uk_hist == NULL ) {
- this->buf_uk_hist = xine_xmalloc( (this->size_uk) );
+ this->buf_uk_hist = malloc(this->size_uk);
xine_fast_memcpy (this->buf_uk_hist, this->buf_uk, this->size_uk);
xine_fast_memcpy (this->index_buf_hist, this->index_buf,
(this->num_pixel * this->bytes_per_pixel));
@@ -1306,20 +1306,12 @@ static void bitplane_decode_data (video_decoder_t *this_gen,
/* when no start-picture is given, create a empty one */
if( this->buf_uk_hist == NULL ) {
this->size_uk = (((this->num_pixel) / 8) * this->num_bitplanes);
- this->buf_uk = xine_xmalloc( (this->size_uk) );
- this->buf_uk_hist = xine_xmalloc( (this->size_uk) );
- for (i = 0; i < this->size_uk; i++) {
- this->buf_uk[i] = 0;
- this->buf_uk_hist[i] = 0;
- }
+ this->buf_uk = calloc(this->num_bitplanes, ((this->num_pixel) / 8));
+ this->buf_uk_hist = calloc(this->num_bitplanes, ((this->num_pixel) / 8));
}
if( this->index_buf == NULL ) {
this->index_buf = calloc( this->num_pixel, this->bytes_per_pixel );
this->index_buf_hist = calloc( this->num_pixel, this->bytes_per_pixel );
- for (i = 0; i < (this->num_pixel * this->bytes_per_pixel); i++) {
- this->index_buf[i] = 0;
- this->index_buf_hist[i] = 0;
- }
}
switch( anhd->operation ) {
diff --git a/src/libxinevdec/rgb.c b/src/libxinevdec/rgb.c
index a94e4b4a1..c1e7f398b 100644
--- a/src/libxinevdec/rgb.c
+++ b/src/libxinevdec/rgb.c
@@ -145,7 +145,7 @@ static void rgb_decode_data (video_decoder_t *this_gen,
/* minimal buffer size */
this->bufsize = this->width * this->height * this->bytes_per_pixel;
- this->buf = xine_xmalloc(this->bufsize);
+ this->buf = calloc(1, this->bufsize);
this->size = 0;
init_yuv_planes(&this->yuv_planes, this->width, this->height);
diff --git a/src/post/audio/upmix_mono.c b/src/post/audio/upmix_mono.c
index caf99a309..2d3429788 100644
--- a/src/post/audio/upmix_mono.c
+++ b/src/post/audio/upmix_mono.c
@@ -192,32 +192,32 @@ static void upmix_mono_port_put_buffer(xine_audio_port_t *port_gen,
_x_extra_info_merge(buf1->extra_info, buf->extra_info);
{
- int step = buf->format.bits / 8;
+ const size_t step = buf->format.bits / 8;
uint8_t *src = (uint8_t *)buf->mem;
uint8_t *dst0 = (uint8_t *)buf0->mem;
uint8_t *dst1 = (uint8_t *)buf1->mem;
- int i, k;
+ int i;
for (i = 0; i < buf->num_frames / 2; i++)
{
- for (k = 0; k < step; k++)
- *dst0++ = *src++;
+ memcpy(dst0, src, step);
+ dst0 += step;
- src -= step;
+ memcpy(dst0, src, step);
+ dst0 += step;
- for (k = 0; k < step; k++)
- *dst0++ = *src++;
+ src += step;
}
for (i = buf->num_frames / 2; i < buf->num_frames; i++)
{
- for (k = 0; k < step; k++)
- *dst1++ = *src++;
+ memcpy(dst1, src, step);
+ dst1 += step;
- src -= step;
+ memcpy(dst1, src, step);
+ dst1 += step;
- for (k = 0; k < step; k++)
- *dst1++ = *src++;
+ src += step;
}
}
@@ -244,11 +244,11 @@ static void upmix_mono_port_put_buffer(xine_audio_port_t *port_gen,
_x_extra_info_merge(buf0->extra_info, buf->extra_info);
{
- int step = buf->format.bits / 8;
+ const size_t step = buf->format.bits / 8;
uint8_t *src = (uint8_t *)buf->mem;
uint8_t *dst0 = (uint8_t *)buf0->mem;
int cur_channel = this->params.channel;
- int i, j, k;
+ int i, j;
if( cur_channel >= this->channels )
cur_channel = this->channels-1;
@@ -259,8 +259,8 @@ static void upmix_mono_port_put_buffer(xine_audio_port_t *port_gen,
{
for (j = 0; j < this->channels; j++ )
{
- for (k = 0; k < step; k++)
- *dst0++ = *(src+k);
+ memcpy(dst0, src, step);
+ dst0 += step;
}
src += this->channels * step;
}
diff --git a/src/post/audio/volnorm.c b/src/post/audio/volnorm.c
index 07d06fe1c..4fdb7dbfc 100644
--- a/src/post/audio/volnorm.c
+++ b/src/post/audio/volnorm.c
@@ -426,9 +426,8 @@ static post_plugin_t *volnorm_open_plugin(post_class_t *class_gen, int inputs,
this->mul = MUL_INIT;
this->lastavg = MID_S16;
this->idx = 0;
- for (i = 0; i < NSAMPLES; i++)
- this->mem[i].len = this->mem[i].avg = 0;
-
+ memset(this->mem, 0, sizeof(this->mem));
+
port = _x_post_intercept_audio_port(&this->post, audio_target[0], &input, &output);
port->new_port.open = volnorm_port_open;
port->new_port.close = volnorm_port_close;
diff --git a/src/post/goom/goom_core.c b/src/post/goom/goom_core.c
index b24f2f496..35fd7fc35 100644
--- a/src/post/goom/goom_core.c
+++ b/src/post/goom/goom_core.c
@@ -841,7 +841,7 @@ void update_message (PluginInfo *goomInfo, char *message) {
if (message) {
int i=1,j=0;
- sprintf (goomInfo->update_message.message, "%s", message);
+ strcpy(goomInfo->update_message.message, message);
for (j=0;goomInfo->update_message.message[j];j++)
if (goomInfo->update_message.message[j]=='\n')
i++;
@@ -855,8 +855,8 @@ void update_message (PluginInfo *goomInfo, char *message) {
char *ptr = msg;
int pos;
float ecart;
+ strncpy(msg, goomInfo->update_message.message, goomInfo->update_message.longueur);
message = msg;
- sprintf (msg, "%s", goomInfo->update_message.message);
while (!fin) {
while (1) {
diff --git a/src/post/mosaico/mosaico.c b/src/post/mosaico/mosaico.c
index 37551aba5..d99bab43b 100644
--- a/src/post/mosaico/mosaico.c
+++ b/src/post/mosaico/mosaico.c
@@ -22,6 +22,10 @@
* simple video mosaico plugin
*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#define LOG_MODULE "mosaico"
#define LOG_VERBOSE
/*
@@ -178,8 +182,7 @@ static post_plugin_t *mosaico_open_plugin(post_class_t *class_gen, int inputs,
this->pip[i].y = 50;
this->pip[i].w = 150;
this->pip[i].h = 150;
- this->pip[i].input_name = (char *)malloc(sizeof("video in ") + 10);
- snprintf(this->pip[i].input_name, sizeof("video in ") + 10, "video in %d", i+1);
+ asprintf(&(this->pip[i].input_name), "video in %d", i+1);
port = _x_post_intercept_video_port(&this->post, video_target[0], &input, NULL);
port->new_port.close = mosaico_close;
diff --git a/src/post/planar/eq2.c b/src/post/planar/eq2.c
index 8894b9d06..0ead54f55 100644
--- a/src/post/planar/eq2.c
+++ b/src/post/planar/eq2.c
@@ -442,26 +442,15 @@ static post_plugin_t *eq2_open_plugin(post_class_t *class_gen, int inputs,
_x_post_init(&this->post, 0, 1);
- eq2 = &this->eq2;
- for (i = 0; i < 3; i++) {
- eq2->buf[i] = NULL;
- eq2->buf_w[i] = 0;
- eq2->buf_h[i] = 0;
-
- eq2->param[i].adjust = NULL;
- eq2->param[i].c = 1.0;
- eq2->param[i].b = 0.0;
- eq2->param[i].g = 1.0;
- eq2->param[i].lut_clean = 0;
- }
-
- eq2->gamma = this->params.gamma = 1.0;
- eq2->contrast = this->params.contrast = 1.0;
- eq2->brightness = this->params.brightness = 0.0;
- eq2->saturation = this->params.saturation = 1.0;
- eq2->rgamma = this->params.rgamma = 1.0;
- eq2->ggamma = this->params.ggamma = 1.0;
- eq2->bgamma = this->params.bgamma = 1.0;
+ memset(&this->eq2, 0, sizeof(this->eq2));
+
+ this->eq2.gamma = this->params.gamma = 1.0;
+ this->eq2.contrast = this->params.contrast = 1.0;
+ this->eq2.brightness = this->params.brightness = 0.0;
+ this->eq2.saturation = this->params.saturation = 1.0;
+ this->eq2.rgamma = this->params.rgamma = 1.0;
+ this->eq2.ggamma = this->params.ggamma = 1.0;
+ this->eq2.bgamma = this->params.bgamma = 1.0;
pthread_mutex_init(&this->lock, NULL);
diff --git a/src/post/planar/pp.c b/src/post/planar/pp.c
index 3c6fe8767..51d28b33d 100644
--- a/src/post/planar/pp.c
+++ b/src/post/planar/pp.c
@@ -20,6 +20,10 @@
* plugin for ffmpeg libpostprocess
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include "xine_internal.h"
#include "post.h"
#include "xineutils.h"
@@ -119,12 +123,9 @@ static char * get_help (void) {
);
static char *help = NULL;
- if( !help ) {
- help = malloc( strlen(help1) + strlen(help2) + strlen(pp_help) + 1);
- strcpy(help, help1);
- strcat(help, pp_help);
- strcat(help, help2);
- }
+ if( !help )
+ asprintf(&help, "%s%s%s", help1, help2, pp_help);
+
return help;
}
diff --git a/src/video_out/video_out_opengl.c b/src/video_out/video_out_opengl.c
index a82bb8f18..9dcfd4f2e 100644
--- a/src/video_out/video_out_opengl.c
+++ b/src/video_out/video_out_opengl.c
@@ -694,10 +694,9 @@ static void *getdladdr (const GLubyte *_funcName) {
return NULL;
#elif defined(__APPLE__)
- char *temp = xine_xmalloc (strlen (funcName) + 2);
+ char *temp;
+ asprintf(&temp, "_%s", funcName);
void *res = NULL;
- temp[0] = '_'; /* Mac OS X prepends an underscore on function names */
- strcpy (temp+1, funcName);
if (NSIsSymbolNameDefined (temp)) {
NSSymbol symbol = NSLookupAndBindSymbol (temp);
res = NSAddressOfSymbol (symbol);
@@ -1876,8 +1875,7 @@ static vo_driver_t *opengl_open_plugin (video_driver_class_t *class_gen, const v
this->drawable, X11OSD_SHAPED);
XUnlockDisplay (this->display);
- render_fun_names = xine_xmalloc ((sizeof(opengl_rb)/sizeof(opengl_render_t)+1)
- * sizeof (const char *));
+ render_fun_names = calloc((sizeof(opengl_rb)/sizeof(opengl_render_t)+1), sizeof(const char*));
for (i = 0; i < sizeof (opengl_rb) / sizeof (opengl_render_t); i++)
render_fun_names[i] = opengl_rb[i].name;
render_fun_names[i] = NULL;
diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c
index 07dafa12d..b016a8bd1 100644
--- a/src/video_out/video_out_xxmc.c
+++ b/src/video_out/video_out_xxmc.c
@@ -162,14 +162,10 @@ static void xxmc_xvmc_surface_handler_construct(xxmc_driver_t *this)
xvmc_surface_handler_t *handler = &this->xvmc_surf_handler;
pthread_mutex_init(&handler->mutex,NULL);
- for (i=0; i<XVMC_MAX_SURFACES; ++i) {
- handler->surfInUse[i] = 0;
- handler->surfValid[i] = 0;
- }
- for (i=0; i<XVMC_MAX_SUBPICTURES; ++i) {
- handler->subInUse[i] = 0;
- handler->subValid[i] = 0;
- }
+ memset(handler->surfInUse, 0, sizeof(handler->surfInUse));
+ memset(handler->surfValid, 0, sizeof(handler->surfValid));
+ memset(handler->subInUse, 0, sizeof(handler->subInUse));
+ memset(handler->subValid, 0, sizeof(handler->subValid));
}
static void xxmc_xvmc_destroy_surfaces(xxmc_driver_t *this)
diff --git a/src/xine-engine/alphablend.c b/src/xine-engine/alphablend.c
index a7ab33cf8..6f3ac3ebe 100644
--- a/src/xine-engine/alphablend.c
+++ b/src/xine-engine/alphablend.c
@@ -1110,12 +1110,12 @@ static uint8_t *(*blend_yuv_grow_extra_data(alphablend_t *extra_data, int osd_wi
uint8_t *data[ 3 ][ 2 ];
} *header = (struct header_s *)extra_data->buffer;
- int needed_buffer_size = sizeof (*header) + osd_width * sizeof (uint8_t[ 3 ][ 2 ]);
+ size_t needed_buffer_size = sizeof (*header) + osd_width * sizeof (uint8_t[ 3 ][ 2 ]);
if (extra_data->buffer_size < needed_buffer_size) {
free(extra_data->buffer);
- header = xine_xmalloc(needed_buffer_size);
+ header = calloc(1, needed_buffer_size);
if (!header) {
extra_data->buffer_size = 0;
return 0;
@@ -1552,12 +1552,12 @@ static uint8_t *(*blend_yuy2_grow_extra_data(alphablend_t *extra_data, int osd_w
uint8_t *data[ 3 ];
} *header = (struct header_s *)extra_data->buffer;
- int needed_buffer_size = sizeof (*header) + osd_width * sizeof (uint8_t[ 3 ]);
+ size_t needed_buffer_size = sizeof (*header) + osd_width * sizeof (uint8_t[ 3 ]);
if (extra_data->buffer_size < needed_buffer_size) {
free(extra_data->buffer);
- header = xine_xmalloc(needed_buffer_size);
+ header = calloc(1, needed_buffer_size);
if (!header) {
extra_data->buffer_size = 0;
return 0;
diff --git a/src/xine-engine/alphablend.h b/src/xine-engine/alphablend.h
index 3c9a693d9..7aa63b306 100644
--- a/src/xine-engine/alphablend.h
+++ b/src/xine-engine/alphablend.h
@@ -39,22 +39,7 @@ typedef struct {
void _x_alphablend_init(alphablend_t *extra_data, xine_t *xine) XINE_PROTECTED;
void _x_alphablend_free(alphablend_t *extra_data) XINE_PROTECTED;
-/* _MSC_VER port changes */
-#undef ATTRIBUTE_PACKED
-#undef PRAGMA_PACK_BEGIN
-#undef PRAGMA_PACK_END
-
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) || defined(__ICC)
-#define ATTRIBUTE_PACKED __attribute__ ((packed))
-#define PRAGMA_PACK 0
-#endif
-
-#if !defined(ATTRIBUTE_PACKED)
-#define ATTRIBUTE_PACKED
-#define PRAGMA_PACK 1
-#endif
-
-#if PRAGMA_PACK
+#if !SUPPORT_ATTRIBUTE_PACKED
#pragma pack(8)
#endif
@@ -63,10 +48,10 @@ typedef struct { /* CLUT == Color LookUp Table */
uint8_t cr;
uint8_t y;
uint8_t foo;
-} ATTRIBUTE_PACKED clut_t;
+} XINE_PACKED clut_t;
-#if PRAGMA_PACK
+#if !SUPPORT_ATTRIBUTE_PACKED
#pragma pack()
#endif
diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h
index ebb308a04..e0dc88bc7 100644
--- a/src/xine-engine/buffer.h
+++ b/src/xine-engine/buffer.h
@@ -627,7 +627,7 @@ uint32_t _x_formattag_to_buf_audio( uint32_t formattag ) XINE_PROTECTED;
char * _x_buf_audio_name( uint32_t buf_type ) XINE_PROTECTED;
-#ifndef ATTRIBUTE_PACKED
+#ifndef SUPPORT_ATTRIBUTE_PACKED
/* no attribute packed? let's try with pragma pack as a last resort */
#pragma pack(2)
#endif
@@ -636,7 +636,7 @@ char * _x_buf_audio_name( uint32_t buf_type ) XINE_PROTECTED;
* - will always use machine endian format, so demuxers reading
* stuff from win32 formats must use the function below.
*/
-typedef struct __attribute__((__packed__)) {
+typedef struct XINE_PACKED {
int32_t biSize;
int32_t biWidth;
int32_t biHeight;
@@ -653,7 +653,7 @@ typedef struct __attribute__((__packed__)) {
/* this is xine version of WAVEFORMATEX
* (the same comments from xine_bmiheader)
*/
-typedef struct __attribute__((__packed__)) {
+typedef struct XINE_PACKED {
int16_t wFormatTag;
int16_t nChannels;
int32_t nSamplesPerSec;
@@ -662,7 +662,7 @@ typedef struct __attribute__((__packed__)) {
int16_t wBitsPerSample;
int16_t cbSize;
} xine_waveformatex;
-#ifndef ATTRIBUTE_PACKED
+#ifndef SUPPORT_ATTRIBUTE_PACKED
#pragma pack()
#endif
diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c
index ed3d2fcfb..ad23f3b30 100644
--- a/src/xine-engine/configfile.c
+++ b/src/xine-engine/configfile.c
@@ -369,8 +369,7 @@ static const char *config_translate_key (const char *key) {
*/
if (!strncmp (key, "decoder.", 8) &&
!strcmp (key + (trans = strlen (key)) - 9, "_priority")) {
- newkey = realloc (newkey, trans + 27 - 17); /* diff. in string lengths */
- sprintf (newkey, "engine.decoder_priorities.%.*s", trans - 17, key + 8);
+ asprintf (&newkey, "engine.decoder_priorities.%.*s", trans - 17, key + 8);
return newkey;
}
diff --git a/src/xine-engine/info_helper.c b/src/xine-engine/info_helper.c
index 2d0ff4d8d..e6d4df7e9 100644
--- a/src/xine-engine/info_helper.c
+++ b/src/xine-engine/info_helper.c
@@ -340,11 +340,10 @@ void _x_meta_info_set_utf8(xine_stream_t *stream, int info, const char *str) {
void _x_meta_info_n_set(xine_stream_t *stream, int info, const char *buf, int len) {
pthread_mutex_lock(&stream->meta_mutex);
if(meta_valid(info) && len) {
- char *str = malloc(len + 1);
+ char *str = strndup(buf, len);
- snprintf(str, len + 1 , "%s", buf);
- meta_info_set_unlocked(stream, info, (const char *) &str[0]);
- free(str);
+ meta_info_set_unlocked(stream, info, str);
+ free(str);
}
pthread_mutex_unlock(&stream->meta_mutex);
}
diff --git a/src/xine-engine/input_cache.c b/src/xine-engine/input_cache.c
index 242449b9f..4eb524af6 100644
--- a/src/xine-engine/input_cache.c
+++ b/src/xine-engine/input_cache.c
@@ -386,7 +386,7 @@ input_plugin_t *_x_cache_plugin_get_instance (xine_stream_t *stream, int readahe
this->buf_size = DEFAULT_BUFFER_SIZE;
}
- this->buf = (char *)xine_xmalloc(this->buf_size);
+ this->buf = calloc(1, this->buf_size);
if (!this->buf) {
free (this);
return NULL;
diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c
index fce31baca..d08837dc5 100644
--- a/src/xine-engine/load_plugins.c
+++ b/src/xine-engine/load_plugins.c
@@ -368,12 +368,13 @@ static void _insert_node (xine_t *this,
info->id);
_x_abort();
}
- for (i=0; decoder_old->supported_types[i] != 0; ++i);
- types = calloc((i+1), sizeof(uint32_t));
- for (i=0; decoder_old->supported_types[i] != 0; ++i){
- types[i] = decoder_old->supported_types[i];
+ {
+ size_t supported_types_size;
+ for (supported_types_size=0; decoder_old->supported_types[supported_types_size] != 0; ++supported_types_size);
+ types = calloc((supported_types_size+1), sizeof(uint32_t));
+ memcpy(types, decoder_old->supported_types, supported_types_size);
+ decoder_new->supported_types = types;
}
- decoder_new->supported_types = types;
entry->priority = decoder_new->priority = decoder_old->priority;
snprintf(key, sizeof(key), "engine.decoder_priorities.%s", info->id);
@@ -382,8 +383,7 @@ static void _insert_node (xine_t *this,
* does not strdup() it, so we have to provide a different pointer
* for each decoder */
for (i = 0; catalog->prio_desc[i]; i++);
- catalog->prio_desc[i] = malloc(strlen(desc) + 1);
- strcpy(catalog->prio_desc[i], desc);
+ catalog->prio_desc[i] = strdup(desc);
this->config->register_num (this->config,
key,
0,
@@ -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);
diff --git a/src/xine-engine/osd.c b/src/xine-engine/osd.c
index 5de0de2cb..ac3c2bb92 100644
--- a/src/xine-engine/osd.c
+++ b/src/xine-engine/osd.c
@@ -1410,7 +1410,6 @@ static void osd_preload_fonts (osd_renderer_t *this, char *path) {
if( p ) {
osd_font_t *font;
- char *pathname;
*p++ = '\0';
font = calloc(1, sizeof(osd_font_t) );
@@ -1421,9 +1420,7 @@ static void osd_preload_fonts (osd_renderer_t *this, char *path) {
lprintf("font '%s' size %d is preloaded\n",
font->name, font->size);
- pathname = malloc(strlen(path) + strlen(entry->d_name) + 2);
- sprintf (pathname, "%s/%s", path, entry->d_name);
- font->filename = pathname;
+ asprintf (&font->filename, "%s/%s", path, entry->d_name);
font->next = this->fonts;
this->fonts = font;
diff --git a/src/xine-engine/scratch.c b/src/xine-engine/scratch.c
index 3be1c70ef..696e99ffb 100644
--- a/src/xine-engine/scratch.c
+++ b/src/xine-engine/scratch.c
@@ -54,8 +54,7 @@ static void __attribute__((__format__(__printf__, 2, 0)))
if ( ! this->lines[this->cur] )
return;
- strftime (this->lines[this->cur], SCRATCH_LINE_LEN_MAX, "%X: ", &tm);
- l = strlen (this->lines[this->cur]);
+ l = strftime (this->lines[this->cur], SCRATCH_LINE_LEN_MAX, "%X: ", &tm);
vsnprintf (this->lines[this->cur] + l, SCRATCH_LINE_LEN_MAX - l, format, argp);
lprintf ("printing format %s to line %d\n", format, this->cur);
diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c
index bbf7bf7fb..fd10a7401 100644
--- a/src/xine-engine/xine.c
+++ b/src/xine-engine/xine.c
@@ -553,7 +553,7 @@ static int stream_rewire_video(xine_post_out_t *output, void *data)
return 1;
}
-void xine_dispose_internal (xine_stream_t *stream);
+static void xine_dispose_internal (xine_stream_t *stream);
xine_stream_t *xine_stream_new (xine_t *this,
xine_audio_port_t *ao, xine_video_port_t *vo) {
@@ -1437,7 +1437,7 @@ int xine_eject (xine_stream_t *stream) {
return status;
}
-void xine_dispose_internal (xine_stream_t *stream) {
+static void xine_dispose_internal (xine_stream_t *stream) {
xine_list_iterator_t *ite;
@@ -1634,8 +1634,7 @@ static void config_save_cb (void *this_gen, xine_cfg_entry_t *entry) {
xine_t *this = (xine_t *)this_gen;
char *homedir_trail_slash;
- homedir_trail_slash = (char *)malloc(strlen(xine_get_homedir()) + 2);
- sprintf(homedir_trail_slash, "%s/", xine_get_homedir());
+ asprintf(&homedir_trail_slash, "%s/", xine_get_homedir());
if (entry->str_value[0] &&
(entry->str_value[0] != '/' || strstr(entry->str_value, "/.") ||
strcmp(entry->str_value, xine_get_homedir()) == 0 ||
@@ -1939,7 +1938,7 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he
uint8_t **img, int *size, int alloc_img) {
vo_frame_t *frame;
- int required_size;
+ size_t required_size;
stream->xine->port_ticket->acquire(stream->xine->port_ticket, 0);
frame = stream->video_out->get_last_frame (stream->video_out);
@@ -1994,7 +1993,7 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he
if (size)
*size = required_size;
/* allocate img or fail */
- if (!(*img = xine_xmalloc (required_size)))
+ if (!(*img = calloc(1, required_size)))
return 0;
} else {
/* fail if supplied buffer is to small */
diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h
index 3d6e66359..29bb9f28f 100644
--- a/src/xine-utils/attributes.h
+++ b/src/xine-utils/attributes.h
@@ -32,20 +32,28 @@
#define ATTR_ALIGN(align)
#endif
-/* disable GNU __attribute__ extension, when not compiling with GNU C */
-#if defined(__GNUC__) || defined (__ICC)
-#ifndef ATTRIBUTE_PACKED
-#define ATTRIBUTE_PACKED 1
-#endif
-#else
-#undef ATTRIBUTE_PACKED
-#ifndef __attribute__
-#define __attribute__(x) /**/
-#endif /* __attribute __*/
-#endif
-
#ifdef XINE_COMPILE
# include "configure.h"
+#else
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95 )
+# define SUPPORT_ATTRIBUTE_PACKED 1
+# endif
+
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 )
+# define SUPPORT_ATTRIBUTE_DEPRECATED 1
+# define SUPPORT_ATTRIBUTE_FORMAT 1
+# define SUPPORT_ATTRIBUTE_FORMAT_ARG 1
+# define SUPPORT_ATTRIBUTE_MALLOC 1
+# define SUPPORT_ATTRIBUTE_UNUSED 1
+# endif
+
+# if __GNUC__ >= 4
+# define SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT 1
+# if __ELF__
+# define SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED 1
+# endif
+# define SUPPORT_ATTRIBUTE_SENTINEL 1
+# endif
#endif
/* Export protected only for libxine functions */
@@ -95,4 +103,10 @@
# define XINE_MALLOC
#endif
+#ifdef SUPPORT_ATTRIBUTE_PACKED
+# define XINE_PACKED __attribute__((__packed__))
+#else
+# define XINE_PACKED
+#endif
+
#endif /* ATTRIBUTE_H_ */
diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c
index fb323055c..301d6c22f 100644
--- a/src/xine-utils/monitor.c
+++ b/src/xine-utils/monitor.c
@@ -39,12 +39,10 @@ static const char *profiler_label[MAX_ID] ;
void xine_profiler_init () {
int i;
- for (i=0; i<MAX_ID; i++) {
- profiler_times[i] = 0;
- profiler_start[i] = 0;
- profiler_calls[i] = 0;
- profiler_label[i] = NULL;
- }
+ memset(profiler_times, 0, sizeof(profiler_times));
+ memset(profiler_start, 0, sizeof(profiler_start));
+ memset(profiler_calls, 0, sizeof(profiler_calls));
+ memset(profiler_label, 0, sizeof(profiler_label));
}
int xine_profiler_allocate_slot (const char *label) {
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index 48ceef688..4085d65ee 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -236,7 +236,25 @@ static const lang_locale_t lang_locales[] = {
{ NULL, NULL, NULL, NULL }
};
-
+/**
+ * @brief Allocate and clean memory size_t 'size', then return the
+ * pointer to the allocated memory.
+ * @param size Size of the memory area to allocate.
+ *
+ * @return A pointer to the allocated memory area, or NULL in case of
+ * error.
+ *
+ * The behaviour of this function differs from standard malloc() as
+ * xine_xmalloc(0) will not return a NULL pointer, but rather a
+ * pointer to a memory area of size 1 byte.
+ *
+ * The NULL value is only ever returned in case of an error in
+ * malloc(), and is reported to stderr stream.
+ *
+ * @deprecated This function has been deprecated, as the behaviour of
+ * allocating a 1 byte memory area on zero size is almost
+ * never desired, and the function is thus mostly misused.
+ */
void *xine_xmalloc(size_t size) {
void *ptr;
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
index 2099bf7f3..89aff96bf 100644
--- a/src/xine-utils/xineutils.h
+++ b/src/xine-utils/xineutils.h
@@ -621,7 +621,7 @@ void xine_profiler_print_results (void) XINE_PROTECTED;
* Allocate and clean memory size_t 'size', then return the pointer
* to the allocated memory.
*/
-void *xine_xmalloc(size_t size) XINE_MALLOC XINE_PROTECTED;
+void *xine_xmalloc(size_t size) XINE_MALLOC XINE_DEPRECATED XINE_PROTECTED;
/*
* Same as above, but memory is aligned to 'alignement'.
diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c
index 09e5a5e24..7da4cc59b 100644
--- a/src/xine-utils/xmllexer.c
+++ b/src/xine-utils/xmllexer.c
@@ -29,7 +29,6 @@
#include "xineutils.h"
#else
#define lprintf(...)
-#define xine_xmalloc malloc
#endif
#include "xmllexer.h"
#include <stdio.h>
@@ -534,7 +533,7 @@ static struct {
char *lexer_decode_entities (const char *tok)
{
- char *buf = xine_xmalloc (strlen (tok) + 1);
+ char *buf = calloc (strlen (tok) + 1, sizeof(char));
char *bp = buf;
char c;