1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

use appropriate functions for string allocation and concatenation

This commit is contained in:
sgerwk 2020-09-29 11:36:36 +02:00
parent 90a141be2b
commit 526b0d0ff9

View File

@ -613,10 +613,11 @@ add_uri_to_string(struct string *string, const struct uri *uri,
if (uri->protocol == PROTOCOL_DATA) {
char *e;
add_bytes_to_string(string,
"data", sizeof("data") - 1);
add_to_string(string, "data");
e = get_extension_from_uri((struct uri *) uri);
return add_bytes_to_string(string, e, strlen(e));
add_to_string(string, e);
mem_free(e);
return string;
}
for (pos = filename; *pos && !end_of_dir(*pos); pos++)
@ -1327,7 +1328,7 @@ get_translated_uri(unsigned char *uristring, unsigned char *cwd)
#define ADD_EXTENSION_FROM_TYPE(string, type, ext) \
if (!memcmp(uri->data, type ";", sizeof(type ";") - 1) || \
!memcmp(uri->data, type ",", sizeof(type ",") - 1)) \
return strdup("." ext);
return stracpy("." ext);
unsigned char *
get_extension_from_uri(struct uri *uri)
@ -1344,7 +1345,7 @@ get_extension_from_uri(struct uri *uri)
ADD_EXTENSION_FROM_TYPE(uri->data, "image/png", "png")
ADD_EXTENSION_FROM_TYPE(uri->data, "text/plain", "txt")
ADD_EXTENSION_FROM_TYPE(uri->data, "text/html", "html")
return "";
return stracpy("");
}
for (; *pos && !end_of_dir(*pos); pos++) {