1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[js] memacpy

This commit is contained in:
Witold Filipczyk 2023-09-28 14:37:28 +02:00
parent 446f6de0e0
commit ecff39f6c3
4 changed files with 12 additions and 10 deletions

View File

@ -240,7 +240,7 @@ set_xhr_header(char *normalized_value, const char *h_name, struct mjs_xhr *x)
}
}
const char *
char *
get_output_headers(struct mjs_xhr *x)
{
std::string output = "";
@ -250,10 +250,10 @@ get_output_headers(struct mjs_xhr *x)
output += h.first + ": " + h.second + "\r\n";
}
return output.c_str();
return memacpy(output.c_str(), output.length());
}
const char *
char *
get_output_header(const char *header_name, struct mjs_xhr *x)
{
std::string output = "";
@ -267,7 +267,7 @@ get_output_header(const char *header_name, struct mjs_xhr *x)
}
if (!output.empty()) {
return output.c_str();
return memacpy(output.c_str(), output.length());
}
return NULL;

View File

@ -44,8 +44,8 @@ void *attr_create_new_responseHeaders_map(void);
void process_xhr_headers(char *head, struct mjs_xhr *x);
void set_xhr_header(char *normalized_value, const char *h_name, struct mjs_xhr *x);
const char *get_output_headers(struct mjs_xhr *x);
const char *get_output_header(const char *header_name, struct mjs_xhr *x);
char *get_output_headers(struct mjs_xhr *x);
char *get_output_header(const char *header_name, struct mjs_xhr *x);
const char *get_elstyle(void *m);
void *set_elstyle(const char *text);

View File

@ -339,13 +339,14 @@ mjs_xhr_getAllResponseHeaders(js_State *J)
js_pushnull(J);
return;
}
const char *output = get_output_headers(xhr);
char *output = get_output_headers(xhr);
if (!output) {
js_pushnull(J);
return;
}
js_pushstring(J, output);
mem_free(output);
}
static void
@ -363,10 +364,11 @@ mjs_xhr_getResponseHeader(js_State *J)
const char *header = js_tostring(J, 1);
if (header) {
const char *output = get_output_header(header, xhr);
char *output = get_output_header(header, xhr);
if (output) {
js_pushstring(J, output);
mem_free(output);
return;
}
}

View File

@ -457,7 +457,7 @@ get_output_headers(struct Xhr *x)
output += h.first + ": " + h.second + "\r\n";
}
return stracpy(output.c_str());
return memacpy(output.c_str(), output.length());
}
char *
@ -474,7 +474,7 @@ get_output_header(const char *header_name, struct Xhr *x)
}
if (!output.empty()) {
return stracpy(output.c_str());
return memacpy(output.c_str(), output.length());
}
return NULL;