From e81d1f6312de85e5640277f5968263aa8cd393db Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 9 Sep 2023 02:30:37 +0200 Subject: main.c: Remove string duplication in get_forms slweb now assumes application/x-www-form-urlencoded-data as text, so it now returns a null-terminated string on struct http_post member "data". This removes the need for slcl to call strdup(3) in order to obtain a null-terminated string. --- main.c | 13 ++----------- slweb | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index 48c6617..f05d589 100644 --- a/main.c +++ b/main.c @@ -208,23 +208,16 @@ static int get_forms(const struct http_payload *const pl, { int ret = -1; const struct http_post *const p = &pl->u.post; - const char *const ref = p->data; - char *dup = NULL; struct form *f = NULL; - if (!ref) + if (!p->data) { fprintf(stderr, "%s: expected non-NULL buffer\n", __func__); ret = 1; goto end; } - else if (!(dup = strndup(ref, p->n))) - { - fprintf(stderr, "%s: strndup(3): %s\n", __func__, strerror(errno)); - goto end; - } - const char *s = dup; + const char *s = p->data; *outn = 0; @@ -241,8 +234,6 @@ static int get_forms(const struct http_payload *const pl, ret = 0; end: - free(dup); - if (ret) forms_free(f, *outn); diff --git a/slweb b/slweb index 34d7160..5be3ffd 160000 --- a/slweb +++ b/slweb @@ -1 +1 @@ -Subproject commit 34d716082a0136056373f3d0c6ed7abce45484b3 +Subproject commit 5be3ffdd3bfd96b314509f6f03e211e309d0fef3 -- cgit v1.2.3