[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnurl] 132/411: curl: make file2string use dynbuf
From: |
gnunet |
Subject: |
[gnurl] 132/411: curl: make file2string use dynbuf |
Date: |
Wed, 13 Jan 2021 01:19:07 +0100 |
This is an automated email from the git hooks/post-receive script.
nikita pushed a commit to branch master
in repository gnurl.
commit 0938f828bfa3c06416e6b4fb1be67340485466f6
Author: Daniel Stenberg <daniel@haxx.se>
AuthorDate: Fri Sep 11 10:49:24 2020 +0200
curl: make file2string use dynbuf
Closes #5952
---
src/tool_paramhlp.c | 41 +++++++++--------------------------------
1 file changed, 9 insertions(+), 32 deletions(-)
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c
index e57daa2e1..f60d4f957 100644
--- a/src/tool_paramhlp.c
+++ b/src/tool_paramhlp.c
@@ -34,6 +34,7 @@
#include "tool_msgs.h"
#include "tool_paramhlp.h"
#include "tool_version.h"
+#include "dynbuf.h"
#include "memdebug.h" /* keep this as LAST include */
@@ -56,51 +57,27 @@ struct getout *new_getout(struct OperationConfig *config)
return node;
}
+#define MAX_FILE2STRING (256*1024*1024) /* big enough ? */
+
ParameterError file2string(char **bufp, FILE *file)
{
- char *string = NULL;
+ struct curlx_dynbuf dyn;
+ curlx_dyn_init(&dyn, MAX_FILE2STRING);
if(file) {
- char *ptr;
- size_t alloc = 512;
- size_t alloc_needed;
char buffer[256];
- size_t stringlen = 0;
- string = calloc(1, alloc);
- if(!string)
- return PARAM_NO_MEM;
while(fgets(buffer, sizeof(buffer), file)) {
- size_t buflen;
- ptr = strchr(buffer, '\r');
+ char *ptr = strchr(buffer, '\r');
if(ptr)
*ptr = '\0';
ptr = strchr(buffer, '\n');
if(ptr)
*ptr = '\0';
- buflen = strlen(buffer);
- alloc_needed = stringlen + buflen + 1;
- if(alloc < alloc_needed) {
-#if SIZEOF_SIZE_T < 8
- if(alloc >= (size_t)SIZE_T_MAX/2) {
- Curl_safefree(string);
- return PARAM_NO_MEM;
- }
-#endif
- /* doubling is enough since the string to add is always max 256 bytes
- and the alloc size start at 512 */
- alloc *= 2;
- ptr = realloc(string, alloc);
- if(!ptr) {
- Curl_safefree(string);
- return PARAM_NO_MEM;
- }
- string = ptr;
- }
- strcpy(string + stringlen, buffer);
- stringlen += buflen;
+ if(curlx_dyn_add(&dyn, buffer))
+ return PARAM_NO_MEM;
}
}
- *bufp = string;
+ *bufp = curlx_dyn_ptr(&dyn);
return PARAM_OK;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnurl] 182/411: ftp: separate FTPS from FTP over "HTTPS proxy", (continued)
- [gnurl] 182/411: ftp: separate FTPS from FTP over "HTTPS proxy", gnunet, 2021/01/12
- [gnurl] 197/411: configure: use "no" instead of "disabled" for the end summary, gnunet, 2021/01/12
- [gnurl] 232/411: CI/tests: use verification curl for test reporting APIs, gnunet, 2021/01/12
- [gnurl] 233/411: strerror: Revert to local codepage for Windows error string, gnunet, 2021/01/12
- [gnurl] 226/411: mbedtls: add missing header when defining MBEDTLS_DEBUG, gnunet, 2021/01/12
- [gnurl] 159/411: CHECKSRC: document two missing warnings, gnunet, 2021/01/12
- [gnurl] 133/411: curl: make file2memory use dynbuf, gnunet, 2021/01/12
- [gnurl] 154/411: man pages: switch to https://example.com URLs, gnunet, 2021/01/12
- [gnurl] 259/411: packages/OS400: make the source code-style compliant, gnunet, 2021/01/12
- [gnurl] 241/411: src/tool_filetime: disable -Wformat on mingw for this file, gnunet, 2021/01/12
- [gnurl] 132/411: curl: make file2string use dynbuf,
gnunet <=
- [gnurl] 180/411: pingpong: use a dynbuf for the *_pp_sendf() function, gnunet, 2021/01/12
- [gnurl] 143/411: test3015: verify stdout "as text", gnunet, 2021/01/12
- [gnurl] 150/411: multi: align WinSock mask variables in Curl_multi_wait, gnunet, 2021/01/12
- [gnurl] 145/411: CI/azure: disable test 571 in the msys2 builds, gnunet, 2021/01/12
- [gnurl] 163/411: docs/RESOURCES: remove, gnunet, 2021/01/12
- [gnurl] 169/411: krb5: merged security.c and krb specific FTP functions in here, gnunet, 2021/01/12
- [gnurl] 179/411: dynbuf: add Curl_dyn_vaddf, gnunet, 2021/01/12
- [gnurl] 137/411: vtls: deduplicate client certificates in ssl_config_data, gnunet, 2021/01/12
- [gnurl] 196/411: TODO: SSH over HTTPS proxy with more backends, gnunet, 2021/01/12
- [gnurl] 138/411: tool_urlglob: fix compiler warning "unreachable code", gnunet, 2021/01/12