summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/input')
-rw-r--r--src/input/http_helper.c3
-rw-r--r--src/input/input_cdda.c75
-rw-r--r--src/input/input_dvd.c5
-rw-r--r--src/input/input_file.c44
-rw-r--r--src/input/input_http.c17
-rw-r--r--src/input/input_pvr.c15
-rw-r--r--src/input/libreal/real.c2
-rw-r--r--src/input/libreal/rmff.c21
-rw-r--r--src/input/libreal/sdpplin.c2
-rw-r--r--src/input/librtsp/rtsp.c45
-rw-r--r--src/input/pnm.c6
-rw-r--r--src/input/vcd/xineplug_inp_vcd.c6
12 files changed, 86 insertions, 155 deletions
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 a1e0b473e..f89697981 100644
--- a/src/input/input_cdda.c
+++ b/src/input/input_cdda.c
@@ -424,10 +424,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -535,10 +534,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -648,10 +646,9 @@ static int read_cdrom_toc(int fd, cdrom_toc *toc) {
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -841,10 +838,9 @@ static int read_cdrom_toc(cdda_input_plugin_t *this_gen, cdrom_toc *toc) {
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -1087,10 +1083,9 @@ static int network_read_cdrom_toc(xine_stream_t *stream, int fd, cdrom_toc *toc)
toc->total_tracks = toc->last_track - toc->first_track + 1;
/* allocate space for the toc entries */
- toc->toc_entries =
- (cdrom_toc_entry *)malloc(toc->total_tracks * sizeof(cdrom_toc_entry));
+ toc->toc_entries = calloc(toc->total_tracks, sizeof(cdrom_toc_entry));
if (!toc->toc_entries) {
- perror("malloc");
+ perror("calloc");
return -1;
}
@@ -1290,42 +1285,29 @@ static void _cdda_mkdir_safe(xine_t *xine, char *path) {
}
/*
- * Make recursive directory creation
+ * Make recursive directory creation (given an absolute pathname)
*/
-static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) {
- char *p, *pp;
- char buf[XINE_PATH_MAX + XINE_NAME_MAX + 1];
- char buf2[XINE_PATH_MAX + XINE_NAME_MAX + 1];
-
- if(path == NULL)
+static void _cdda_mkdir_recursive_safe (xine_t *xine, char *path)
+{
+ if (!path)
return;
- memset(&buf, 0, sizeof(buf));
- memset(&buf2, 0, sizeof(buf2));
+ char buf[strlen (path) + 1];
+ strcpy (buf, path);
+ char *p = strchr (buf, '/') ? : buf;
- snprintf(buf, sizeof(buf), "%s", path);
- pp = buf;
- while((p = xine_strsep(&pp, "/")) != NULL) {
- if(p && strlen(p)) {
-
-#ifdef WIN32
- if (*buf2 != '\0') {
-#endif
-
- int size = strlen(buf2);
- snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p);
-
-#ifdef WIN32
- }
- else {
- snprintf(buf2, sizeof(buf2), "%s", p);
- }
-
-#endif /* WIN32 */
+ do
+ {
+ while (*p++ == '/') /**/;
+ p = strchr (p, '/');
+ if (p)
+ *p = 0;
+ _cdda_mkdir_safe (xine, buf);
+ if (p)
+ *p = '/';
+ } while (p);
- _cdda_mkdir_safe(xine, buf2);
- }
- }
+ return 0;
}
/*
@@ -1445,7 +1427,6 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) {
while((pdir = readdir(dir)) != NULL) {
char discid[9];
- memset(&discid, 0, sizeof(discid));
snprintf(discid, sizeof(discid), "%08lx", this->cddb.disc_id);
if(!strcasecmp(pdir->d_name, discid)) {
diff --git a/src/input/input_dvd.c b/src/input/input_dvd.c
index 446b7c778..8656097bc 100644
--- a/src/input/input_dvd.c
+++ b/src/input/input_dvd.c
@@ -1374,10 +1374,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;
diff --git a/src/input/input_file.c b/src/input/input_file.c
index 1916a71e4..1556afb09 100644
--- a/src/input/input_file.c
+++ b/src/input/input_file.c
@@ -337,7 +337,7 @@ static int file_plugin_open (input_plugin_t *this_gen ) {
lprintf("file_plugin_open\n");
- if (strncasecmp (this->mrl, "file:", 5) == 0)
+ if (strncasecmp (this->mrl, "file:/", 6) == 0)
{
if (strncasecmp (this->mrl, "file://localhost/", 16) == 0)
filename = decode_uri(&(this->mrl[16]));
@@ -347,43 +347,27 @@ static int file_plugin_open (input_plugin_t *this_gen ) {
filename = decode_uri(&(this->mrl[5]));
}
else
- filename = decode_uri(this->mrl);
+ filename = strdup(this->mrl); /* NEVER unescape plain file names! */
this->fh = open (filename, O_RDONLY|O_BINARY);
-
- free(filename);
if (this->fh == -1) {
- /* try again without unescaping; such MRLs might be invalid,
- * but we are a nice software */
- if (strncasecmp (this->mrl, "file:", 5) == 0)
- {
- if (strncasecmp (this->mrl, "file://localhost/", 16) == 0)
- this->fh = open(&this->mrl[16], O_RDONLY|O_BINARY);
- else if (strncasecmp (this->mrl, "file://127.0.0.1/", 16) == 0)
- this->fh = open(&this->mrl[16], O_RDONLY|O_BINARY);
- else
- this->fh = open(&this->mrl[5], O_RDONLY|O_BINARY);
+ if (errno == EACCES) {
+ _x_message(this->stream, XINE_MSG_PERMISSION_ERROR, this->mrl, NULL);
+ xine_log (this->stream->xine, XINE_LOG_MSG,
+ _("input_file: Permission denied: >%s<\n"), this->mrl);
+ } else if (errno == ENOENT) {
+ _x_message(this->stream, XINE_MSG_FILE_NOT_FOUND, this->mrl, NULL);
+ xine_log (this->stream->xine, XINE_LOG_MSG,
+ _("input_file: File not found: >%s<\n"), this->mrl);
}
- else
- this->fh = open(this->mrl, O_RDONLY|O_BINARY);
-
- if (this->fh == -1) {
- if (errno == EACCES) {
- _x_message(this->stream, XINE_MSG_PERMISSION_ERROR, this->mrl, NULL);
- xine_log (this->stream->xine, XINE_LOG_MSG,
- _("input_file: Permission denied: >%s<\n"), this->mrl);
- return -1;
- } else if (errno == ENOENT) {
- _x_message(this->stream, XINE_MSG_FILE_NOT_FOUND, this->mrl, NULL);
- xine_log (this->stream->xine, XINE_LOG_MSG,
- _("input_file: File not found: >%s<\n"), this->mrl);
- }
- return -1;
- }
+ free(filename);
+ return -1;
}
+ free(filename);
+
#ifdef HAVE_MMAP
this->mmap_on = 0;
this->mmap_base = NULL;
diff --git a/src/input/input_http.c b/src/input/input_http.c
index 38658b161..f2e91c226 100644
--- a/src/input/input_http.c
+++ b/src/input/input_http.c
@@ -79,9 +79,6 @@ typedef struct {
char buf[BUFSIZE];
char proxybuf[BUFSIZE];
- char auth[BUFSIZE];
- char proxyauth[BUFSIZE];
-
char preview[MAX_PREVIEW_SIZE];
off_t preview_size;
@@ -232,7 +229,7 @@ static int _x_use_proxy(http_input_class_t *this, const char *host) {
}
static int http_plugin_basicauth (const char *user, const char *password, char* dest, int len) {
- static char *enctable="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ static const char enctable[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
char *tmp;
char *sptr;
char *dptr;
@@ -249,7 +246,7 @@ static int http_plugin_basicauth (const char *user, const char *password, char*
if (len < enclen)
return -1;
- tmp = malloc (sizeof(char) * (totlen + 1));
+ tmp = malloc (totlen + 1);
strcpy (tmp, user);
strcat (tmp, ":");
if (password != NULL)
@@ -667,6 +664,8 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
int use_proxy;
int proxyport;
int mpegurl_redirect = 0;
+ char auth[BUFSIZE];
+ char proxyauth[BUFSIZE];
use_proxy = this_class->proxyhost && strlen(this_class->proxyhost);
@@ -674,7 +673,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
if (this_class->proxyuser && strlen(this_class->proxyuser)) {
if (http_plugin_basicauth (this_class->proxyuser,
this_class->proxypassword,
- this->proxyauth, BUFSIZE)) {
+ proxyauth, BUFSIZE)) {
_x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "proxy error", NULL);
return 0;
}
@@ -693,7 +692,7 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
this->port = DEFAULT_HTTP_PORT;
if (this->user && strlen(this->user)) {
- if (http_plugin_basicauth (this->user, this->password, this->auth, BUFSIZE)) {
+ if (http_plugin_basicauth (this->user, this->password, auth, BUFSIZE)) {
_x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "basic auth error", NULL);
return -1;
}
@@ -776,12 +775,12 @@ static int http_plugin_open (input_plugin_t *this_gen ) {
buflen = strlen(this->buf);
if (this_class->proxyuser && strlen(this_class->proxyuser)) {
snprintf (this->buf + buflen, BUFSIZE - buflen,
- "Proxy-Authorization: Basic %s\015\012", this->proxyauth);
+ "Proxy-Authorization: Basic %s\015\012", proxyauth);
buflen = strlen(this->buf);
}
if (this->user && strlen(this->user)) {
snprintf (this->buf + buflen, BUFSIZE - buflen,
- "Authorization: Basic %s\015\012", this->auth);
+ "Authorization: Basic %s\015\012", auth);
buflen = strlen(this->buf);
}
diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c
index ac7c5f2f0..40bb9dc79 100644
--- a/src/input/input_pvr.c
+++ b/src/input/input_pvr.c
@@ -511,10 +511,7 @@ static char *make_temp_name(pvr_input_plugin_t *this, int page) {
char *filename;
- int size = strlen(this->tmp_prefix)+PVR_FILENAME_SIZE;
- filename = malloc(size);
-
- snprintf(filename, size, PVR_FILENAME, this->tmp_prefix, this->session, page);
+ asprintf(&filename, PVR_FILENAME, this->tmp_prefix, this->session, page);
return filename;
}
@@ -527,12 +524,9 @@ static char *make_base_save_name(int channel, time_t tm) {
struct tm rec_time;
char *filename;
- int size = SAVE_BASE_FILENAME_SIZE;
- filename = malloc(size);
-
localtime_r(&tm, &rec_time);
- snprintf(filename, size, SAVE_BASE_FILENAME,
+ asprintf(&filename, SAVE_BASE_FILENAME,
channel, rec_time.tm_mon+1, rec_time.tm_mday,
rec_time.tm_year+1900, rec_time.tm_hour, rec_time.tm_min,
rec_time.tm_sec);
@@ -546,10 +540,7 @@ static char *make_save_name(pvr_input_plugin_t *this, char *base, int page) {
char *filename;
- int size = strlen(this->save_prefix)+strlen(base)+SAVE_FILENAME_SIZE;
- filename = malloc(size);
-
- snprintf(filename, size, SAVE_FILENAME, this->save_prefix, base, page);
+ asprintf(&filename, SAVE_FILENAME, this->save_prefix, base, page);
return filename;
}
diff --git a/src/input/libreal/real.c b/src/input/libreal/real.c
index 9ea65d9df..925b0fdf8 100644
--- a/src/input/libreal/real.c
+++ b/src/input/libreal/real.c
@@ -660,7 +660,7 @@ rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwid
lprintf("Stream description size: %i\n", size);
- description = malloc(sizeof(char)*(size+1));
+ description = calloc(size+1, sizeof(char));
if( rtsp_read_data(rtsp_session, description, size) <= 0) {
xine_buffer_free(buf);
diff --git a/src/input/libreal/rmff.c b/src/input/libreal/rmff.c
index e942fe4cc..4fea74636 100644
--- a/src/input/libreal/rmff.c
+++ b/src/input/libreal/rmff.c
@@ -311,17 +311,17 @@ static rmff_mdpr_t *rmff_scan_mdpr(const char *data) {
mdpr->duration=_X_BE_32(&data[36]);
mdpr->stream_name_size=data[40];
- mdpr->stream_name = malloc(sizeof(char)*(mdpr->stream_name_size+1));
+ mdpr->stream_name = calloc(mdpr->stream_name_size+1, sizeof(char));
memcpy(mdpr->stream_name, &data[41], mdpr->stream_name_size);
mdpr->stream_name[mdpr->stream_name_size]=0;
mdpr->mime_type_size=data[41+mdpr->stream_name_size];
- mdpr->mime_type = malloc(sizeof(char)*(mdpr->mime_type_size+1));
+ mdpr->mime_type = calloc(mdpr->mime_type_size+1, sizeof(char));
memcpy(mdpr->mime_type, &data[42+mdpr->stream_name_size], mdpr->mime_type_size);
mdpr->mime_type[mdpr->mime_type_size]=0;
mdpr->type_specific_len=_X_BE_32(&data[42+mdpr->stream_name_size+mdpr->mime_type_size]);
- mdpr->type_specific_data = malloc(sizeof(char)*(mdpr->type_specific_len));
+ mdpr->type_specific_data = calloc(mdpr->type_specific_len, sizeof(char));
memcpy(mdpr->type_specific_data,
&data[46+mdpr->stream_name_size+mdpr->mime_type_size], mdpr->type_specific_len);
@@ -341,22 +341,22 @@ static rmff_cont_t *rmff_scan_cont(const char *data) {
lprintf("warning: unknown object version in CONT: 0x%04x\n", cont->object_version);
}
cont->title_len=_X_BE_16(&data[10]);
- cont->title = malloc(sizeof(char)*(cont->title_len+1));
+ cont->title = calloc((cont->title_len+1), sizeof(char));
memcpy(cont->title, &data[12], cont->title_len);
cont->title[cont->title_len]=0;
pos=cont->title_len+12;
cont->author_len=_X_BE_16(&data[pos]);
- cont->author = malloc(sizeof(char)*(cont->author_len+1));
+ cont->author = calloc(cont->author_len+1, sizeof(char));
memcpy(cont->author, &data[pos+2], cont->author_len);
cont->author[cont->author_len]=0;
pos=pos+2+cont->author_len;
cont->copyright_len=_X_BE_16(&data[pos]);
- cont->copyright = malloc(sizeof(char)*(cont->copyright_len+1));
+ cont->copyright = calloc(cont->copyright_len+1, sizeof(char));
memcpy(cont->copyright, &data[pos+2], cont->copyright_len);
cont->copyright[cont->copyright_len]=0;
pos=pos+2+cont->copyright_len;
cont->comment_len=_X_BE_16(&data[pos]);
- cont->comment = malloc(sizeof(char)*(cont->comment_len+1));
+ cont->comment = calloc(cont->comment_len+1, sizeof(char));
memcpy(cont->comment, &data[pos+2], cont->comment_len);
cont->comment[cont->comment_len]=0;
@@ -404,10 +404,7 @@ rmff_header_t *rmff_scan_header(const char *data) {
header->fileheader=rmff_scan_fileheader(ptr);
ptr += header->fileheader->size;
- header->streams = malloc(sizeof(rmff_mdpr_t*)*(header->fileheader->num_headers));
- for (i=0; i<header->fileheader->num_headers; i++) {
- header->streams[i]=NULL;
- }
+ header->streams = calloc(header->fileheader->num_headers, sizeof(rmff_mdpr_t*));
for (i=1; i<header->fileheader->num_headers; i++) {
chunk_type = _X_BE_32(ptr);
@@ -587,7 +584,7 @@ rmff_mdpr_t *rmff_new_mdpr(
mdpr->mime_type_size=strlen(mime_type);
}
mdpr->type_specific_len=type_specific_len;
- mdpr->type_specific_data = malloc(sizeof(char)*type_specific_len);
+ mdpr->type_specific_data = calloc(type_specific_len, sizeof(char));
memcpy(mdpr->type_specific_data,type_specific_data,type_specific_len);
mdpr->mlti_data=NULL;
diff --git a/src/input/libreal/sdpplin.c b/src/input/libreal/sdpplin.c
index 3bc5af608..ad65bd491 100644
--- a/src/input/libreal/sdpplin.c
+++ b/src/input/libreal/sdpplin.c
@@ -236,7 +236,7 @@ sdpplin_t *sdpplin_parse(char *data) {
if(filter(data,"a=StreamCount:integer;",&buf)) {
desc->stream_count=atoi(buf);
- desc->stream = malloc(sizeof(sdpplin_stream_t*)*desc->stream_count);
+ desc->stream = calloc(desc->stream_count, sizeof(sdpplin_stream_t*));
handled=1;
data=nl(data);
}
diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c
index a44d0e8e1..d0f09d563 100644
--- a/src/input/librtsp/rtsp.c
+++ b/src/input/librtsp/rtsp.c
@@ -21,6 +21,8 @@
* *not* RFC 2326 compilant yet.
*/
+#include <config.h>
+
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
@@ -103,8 +105,7 @@ const char rtsp_protocol_version[]="RTSP/1.0";
*/
static char *rtsp_get(rtsp_t *s) {
-
- char *buffer = malloc(BUF_SIZE);
+ char buffer[BUF_SIZE];
char *string = NULL;
if ( _x_io_tcp_read_line(s->stream, s->s, buffer, BUF_SIZE) >= 0 ) {
@@ -112,7 +113,6 @@ static char *rtsp_get(rtsp_t *s) {
string = strdup( buffer );
}
- free(buffer);
return string;
}
@@ -124,7 +124,7 @@ static char *rtsp_get(rtsp_t *s) {
static void rtsp_put(rtsp_t *s, const char *string) {
int len=strlen(string);
- char *buf = malloc(sizeof(char)*len+2);
+ char buf[len+2];
lprintf(">> '%s'", string);
@@ -135,8 +135,6 @@ static void rtsp_put(rtsp_t *s, const char *string) {
_x_io_tcp_write(s->stream, s->s, buf, len+2);
lprintf("done.\n");
-
- free(buf);
}
/*
@@ -171,13 +169,11 @@ static int rtsp_get_code(rtsp_t *s, const char *string) {
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);
+ char buf[strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3];
sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version);
rtsp_put(s,buf);
- free(buf);
+
if (payload)
while (*payload) {
rtsp_put(s,*payload);
@@ -199,11 +195,9 @@ static void rtsp_schedule_standard(rtsp_t *s) {
rtsp_schedule_field(s, tmp);
if (s->session) {
- char *buf;
- buf = malloc(strlen(s->session)+15);
+ char buf[strlen(s->session)+15];
sprintf(buf, "Session: %s", s->session);
rtsp_schedule_field(s, buf);
- free(buf);
}
}
/*
@@ -241,14 +235,13 @@ static int rtsp_get_answers(rtsp_t *s) {
}
}
if (!strncasecmp(answer,"Server:",7)) {
- char *buf = xine_xmalloc(strlen(answer));
+ char buf[strlen(answer)];
sscanf(answer,"%*s %s",buf);
if (s->server) free(s->server);
s->server=strdup(buf);
- free(buf);
}
if (!strncasecmp(answer,"Session:",8)) {
- char *buf = xine_xmalloc(strlen(answer));
+ char buf[strlen(answer)];
sscanf(answer,"%*s %s",buf);
if (s->session) {
if (strcmp(buf, s->session)) {
@@ -263,7 +256,6 @@ static int rtsp_get_answers(rtsp_t *s) {
s->session=strdup(buf);
}
- free(buf);
}
*answer_ptr=answer;
answer_ptr++;
@@ -304,8 +296,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 +312,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 +335,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 +351,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 +400,7 @@ int rtsp_read_data(rtsp_t *s, void *buffer_gen, 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 +473,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 38d65b850..942e52957 100644
--- a/src/input/pnm.c
+++ b/src/input/pnm.c
@@ -21,6 +21,8 @@
* based upon code from joschka
*/
+#include <config.h>
+
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
@@ -732,9 +734,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 45d9789ba..b794331f1 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);
+ LOG_ERR("Can't strndup %zu bytes for MRL name %s", strlen(mrl), mrl);
}
(*i)++;
}