mirror of
https://github.com/mpv-player/mpv
synced 2025-01-01 04:36:24 +01:00
Added initialisation of URL pointers.
Added null terminaison to string. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@841 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
7b48f8d38e
commit
fffaf83e4b
18
url.c
18
url.c
@ -16,6 +16,13 @@ set_url(char* url) {
|
|||||||
printf("Memory allocation failed!\n");
|
printf("Memory allocation failed!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
// Initialisation of the URL container members
|
||||||
|
Curl->url = NULL;
|
||||||
|
Curl->protocol = NULL;
|
||||||
|
Curl->hostname = NULL;
|
||||||
|
Curl->file = NULL;
|
||||||
|
Curl->port = 0;
|
||||||
|
|
||||||
// Copy the url in the URL container
|
// Copy the url in the URL container
|
||||||
Curl->url = (char*)malloc(strlen(url)+1);
|
Curl->url = (char*)malloc(strlen(url)+1);
|
||||||
if( Curl->url==NULL ) {
|
if( Curl->url==NULL ) {
|
||||||
@ -27,7 +34,7 @@ set_url(char* url) {
|
|||||||
// extract the protocol
|
// extract the protocol
|
||||||
ptr1 = strstr(url, "://");
|
ptr1 = strstr(url, "://");
|
||||||
if( ptr1==NULL ) {
|
if( ptr1==NULL ) {
|
||||||
printf("Malformed URL!\n");
|
printf("Malformed URL or not an URL!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pos1 = ptr1-url;
|
pos1 = ptr1-url;
|
||||||
@ -62,6 +69,7 @@ set_url(char* url) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
strncpy(Curl->hostname, ptr1+3, pos2-pos1-3);
|
strncpy(Curl->hostname, ptr1+3, pos2-pos1-3);
|
||||||
|
Curl->hostname[pos2-pos1-3] = '\0';
|
||||||
|
|
||||||
// Look if a path is given
|
// Look if a path is given
|
||||||
ptr2 = strstr(ptr1+3, "/");
|
ptr2 = strstr(ptr1+3, "/");
|
||||||
@ -70,12 +78,12 @@ set_url(char* url) {
|
|||||||
// check if it's not a trailing '/'
|
// check if it's not a trailing '/'
|
||||||
if( strlen(ptr2)>1 ) {
|
if( strlen(ptr2)>1 ) {
|
||||||
// copy the path/filename in the URL container
|
// copy the path/filename in the URL container
|
||||||
Curl->path = (char*)malloc(strlen(ptr2));
|
Curl->file = (char*)malloc(strlen(ptr2));
|
||||||
if( Curl->path==NULL ) {
|
if( Curl->file==NULL ) {
|
||||||
printf("Memory allocation failed!\n");
|
printf("Memory allocation failed!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
strcpy(Curl->path, ptr2+1);
|
strcpy(Curl->file, ptr2+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +96,6 @@ free_url(URL_t* url) {
|
|||||||
if(url->url) free(url->url);
|
if(url->url) free(url->url);
|
||||||
if(url->protocol) free(url->protocol);
|
if(url->protocol) free(url->protocol);
|
||||||
if(url->hostname) free(url->hostname);
|
if(url->hostname) free(url->hostname);
|
||||||
if(url->path) free(url->path);
|
if(url->file) free(url->file);
|
||||||
free(url);
|
free(url);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user