1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[quickjs] stracpy to avoid warnings

This commit is contained in:
Witold Filipczyk 2023-09-28 14:31:10 +02:00
parent 42abf0b058
commit 446f6de0e0
3 changed files with 19 additions and 9 deletions

View File

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

View File

@ -72,8 +72,8 @@ void attr_erase_from_map_rev(void *m, JSValueConst value);
void process_xhr_headers(char *head, struct Xhr *x);
void set_xhr_header(char *normalized_value, const char *h_name, struct Xhr *x);
const char *get_output_headers(struct Xhr *x);
const char *get_output_header(const char *header_name, struct Xhr *x);
char *get_output_headers(struct Xhr *x);
char *get_output_header(const char *header_name, struct Xhr *x);
const char *get_elstyle(void *m);
void *set_elstyle(const char *text);

View File

@ -929,14 +929,22 @@ xhr_getallresponseheaders(JSContext *ctx, JSValueConst this_val, int argc, JSVal
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
JSValue ret;
struct Xhr *x = xhr_get(ctx, this_val);
char *output;
if (!x) {
return JS_EXCEPTION;
}
output = get_output_headers(x);
return JS_NewString(ctx, get_output_headers(x));
if (output) {
ret = JS_NewString(ctx, output);
mem_free(output);
return ret;
}
return JS_NULL;
}
static JSValue
@ -955,10 +963,12 @@ xhr_getresponseheader(JSContext *ctx, JSValueConst this_val, int argc, JSValueCo
const char *header_name = JS_ToCString(ctx, argv[0]);
if (header_name) {
const char *output = get_output_header(header_name, x);
char *output = get_output_header(header_name, x);
if (output) {
return JS_NewString(ctx, output);
JSValue ret = JS_NewString(ctx, output);
mem_free(output);
return ret;
}
}
return JS_NULL;