curl/mprintf.h: remove support for _MPRINTF_REPLACE

The define is not in our name space and is therefore not protected by
our API promises.

It was only really used by libcurl internals but was mostly erased from
there already in 8aabbf5 (March 2015). This is supposedly the final
death blow to that define from everywhere.

As a side-effect, making sure _MPRINTF_REPLACE is gone and not used, I
made the lib tests in tests/libtest/ use curl_printf.h for its redefine
magic and then subsequently the use of sprintf() got banned in the tests
as well (as it is in libcurl internals) and I then replaced them all
with snprintf().

In the unlikely event that any users is actually using this define and
gets sad by this change, it is very easily copied to the user's own
code.
This commit is contained in:
Daniel Stenberg 2016-04-01 10:14:06 +02:00
parent 7218b52c49
commit 55452ebdff
16 changed files with 149 additions and 175 deletions

View File

@ -5,7 +5,7 @@
.\" * | (__| |_| | _ <| |___
.\" * \___|\___/|_| \_\_____|
.\" *
.\" * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
.\" * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
.\" *
.\" * This software is licensed as described in the file COPYING, which
.\" * you should have received as part of this distribution. The terms
@ -91,15 +91,9 @@ returned string must be free()ed by the receiver.
Like curl_maprintf() but takes a va_list pointer argument instead of a
variable amount of arguments.
.RE
To easily use all these cloned functions instead of the normal ones, #define
_MPRINTF_REPLACE before you include the <curl/mprintf.h> file. Then all the
normal names like printf, fprintf, sprintf etc will use the curl-functions
instead.
.SH AVAILABILITY
These function will be removed from the public libcurl API in a near
future. They will instead be made "available" by source code access only, and
then as curlx_-prefixed functions. See lib/README.curlx for further details.
These functions will be removed from the public libcurl API in the future. Do
not use them in any new programs or projects.
.SH RETURN VALUE
The \fBcurl_maprintf\fP and \fBcurl_mvaprintf\fP functions return a pointer to
a newly allocated string, or NULL if it failed.

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -24,8 +24,7 @@
#include <stdarg.h>
#include <stdio.h> /* needed for FILE */
#include "curl.h"
#include "curl.h" /* for CURL_EXTERN */
#ifdef __cplusplus
extern "C" {
@ -44,29 +43,6 @@ CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength,
CURL_EXTERN char *curl_maprintf(const char *format, ...);
CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args);
#ifdef _MPRINTF_REPLACE
# undef printf
# undef fprintf
# undef sprintf
# undef vsprintf
# undef snprintf
# undef vprintf
# undef vfprintf
# undef vsnprintf
# undef aprintf
# undef vaprintf
# define printf curl_mprintf
# define fprintf curl_mfprintf
# define sprintf curl_msprintf
# define vsprintf curl_mvsprintf
# define snprintf curl_msnprintf
# define vprintf curl_mvprintf
# define vfprintf curl_mvfprintf
# define vsnprintf curl_mvsnprintf
# define aprintf curl_maprintf
# define vaprintf curl_mvaprintf
#endif
#ifdef __cplusplus
}
#endif

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1999 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1999 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -36,11 +36,6 @@
*/
#include "curl_setup.h"
#if defined(DJGPP) && (DJGPP_MINOR < 4)
#undef _MPRINTF_REPLACE /* don't use x_was_used() here */
#endif
#include <curl/mprintf.h>
#include "curl_memory.h"

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -51,7 +51,8 @@ int test(char *URL)
/* DNS cache injection */
struct curl_slist *dns_cache_list;
sprintf(redirect, "google.com:%s:%s", libtest_arg2, libtest_arg3);
snprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
libtest_arg3);
start_test_timing();

View File

@ -46,7 +46,7 @@ int test(char *URL)
/* Create fake DNS entries for serverX.example.com for all handles */
for(i=0; i < NUM_HANDLES; i++) {
sprintf(dnsentry, "server%d.example.com:%s:%s", i + 1, port, address);
snprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1, port, address);
printf("%s\n", dnsentry);
slist2 = curl_slist_append(slist, dnsentry);
if(!slist2) {
@ -69,7 +69,8 @@ int test(char *URL)
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
sprintf(target_url, "http://server%d.example.com:%s/path/1506%04i",
snprintf(target_url, sizeof(target_url),
"http://server%d.example.com:%s/path/1506%04i",
i + 1, port, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl[i], CURLOPT_URL, target_url);

View File

@ -44,7 +44,7 @@ int test(char *URL)
/* Create fake DNS entries for serverX.example.com for all handles */
for(i=0; i < NUM_URLS; i++) {
sprintf(dnsentry, "server%d.example.com:%s:%s", i + 1, port, address);
snprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1, port, address);
printf("%s\n", dnsentry);
slist2 = curl_slist_append(slist, dnsentry);
if(!slist2) {
@ -73,7 +73,8 @@ int test(char *URL)
/* get NUM_HANDLES easy handles */
for(i=0; i < NUM_URLS; i++) {
/* specify target */
sprintf(target_url, "http://server%d.example.com:%s/path/1510%04i",
snprintf(target_url, sizeof(target_url),
"http://server%d.example.com:%s/path/1510%04i",
i + 1, port, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl, CURLOPT_URL, target_url);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2013, Linus Nielsen Feltzing <linus@haxx.se>
* Copyright (C) 2013 - 2016, Linus Nielsen Feltzing <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -49,7 +49,7 @@ int test(char *URL)
return TEST_ERR_MAJOR_BAD;
}
sprintf(dnsentry, "server.example.curl:%s:%s", port, address);
snprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s", port, address);
printf("%s\n", dnsentry);
slist = curl_slist_append(slist, dnsentry);
@ -58,7 +58,8 @@ int test(char *URL)
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
sprintf(target_url, "http://server.example.curl:%s/path/1512%04i",
snprintf(target_url, sizeof(target_url),
"http://server.example.curl:%s/path/1512%04i",
port, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl[i], CURLOPT_URL, target_url);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2013, Linus Nielsen Feltzing, <linus@haxx.se>
* Copyright (C) 2013 - 2016, Linus Nielsen Feltzing, <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -113,7 +113,7 @@ static void setup_handle(char *base_url, CURLM *m, int handlenum)
{
char urlbuf[256];
sprintf(urlbuf, "%s%s", base_url, urlstring[handlenum]);
snprintf(urlbuf, sizeof(urlbuf), "%s%s", base_url, urlstring[handlenum]);
curl_easy_setopt(handles[handlenum], CURLOPT_URL, urlbuf);
curl_easy_setopt(handles[handlenum], CURLOPT_VERBOSE, 1L);
curl_easy_setopt(handles[handlenum], CURLOPT_FAILONERROR, 1L);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -57,9 +57,9 @@ static char msgbuff[256];
static void store_errmsg(const char *msg, int err)
{
if (!err)
sprintf(msgbuff, "%s", msg);
snprintf(msgbuff, sizeof(msgbuff), "%s", msg);
else
sprintf(msgbuff, "%s, errno %d, %s", msg, err, strerror(err));
snprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, err, strerror(err));
}
static void close_file_descriptors(void)
@ -133,7 +133,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_cur);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "initial soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
@ -141,7 +141,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "initial hard limit: %s\n", strbuff);
/* show our constants */
@ -199,7 +199,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_cur);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "current soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
@ -207,7 +207,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "current hard limit: %s\n", strbuff);
} /* (rl.rlim_cur != rl.rlim_max) */
@ -234,9 +234,9 @@ static int rlimit(int keep_open)
(rl.rlim_cur != RLIM_INFINITY) &&
#endif
(rl.rlim_cur <= num_open.rlim_cur)) {
sprintf(strbuff2, fmt, rl.rlim_cur);
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "fds needed %s > system limit %s",
snprintf(strbuff2, sizeof(strbuff2), fmt, rl.rlim_cur);
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s",
strbuff1, strbuff2);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
@ -258,7 +258,7 @@ static int rlimit(int keep_open)
nitems = 0x40000;
do {
num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems;
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
if (!memchunk) {
@ -286,8 +286,8 @@ static int rlimit(int keep_open)
/* verify that we won't overflow size_t in malloc() */
if ((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
sprintf(strbuff1, fmt, num_open.rlim_max);
sprintf(strbuff, "unable to allocate an array for %s "
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s "
"file descriptors, would overflow size_t", strbuff1);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
@ -297,7 +297,7 @@ static int rlimit(int keep_open)
/* allocate array for file descriptors */
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "allocating array for %s file descriptors\n", strbuff);
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
@ -317,14 +317,14 @@ static int rlimit(int keep_open)
num_open.rlim_cur++)
fd[num_open.rlim_cur] = -1;
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "trying to open %s file descriptors\n", strbuff);
/* open a dummy descriptor */
fd[0] = open(DEV_NULL, O_RDONLY);
if (fd[0] < 0) {
sprintf(strbuff, "opening of %s failed", DEV_NULL);
snprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
store_errmsg(strbuff, ERRNO);
fprintf(stderr, "%s\n", msgbuff);
free(fd);
@ -345,19 +345,19 @@ static int rlimit(int keep_open)
fd[num_open.rlim_cur] = -1;
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "dup() attempt %s failed", strbuff1);
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
fprintf(stderr, "%s\n", strbuff);
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "fds system limit seems close to %s", strbuff1);
snprintf(strbuff1, sizeof(strbuff), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", strbuff1);
fprintf(stderr, "%s\n", strbuff);
num_open.rlim_max = NUM_NEEDED;
sprintf(strbuff2, fmt, num_open.rlim_max);
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "fds needed %s > system limit %s",
snprintf(strbuff2, sizeof(strbuff2), fmt, num_open.rlim_max);
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s",
strbuff2, strbuff1);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
@ -375,7 +375,7 @@ static int rlimit(int keep_open)
}
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "%s file descriptors open\n", strbuff);
#if !defined(HAVE_POLL_FINE) && \
@ -395,7 +395,8 @@ static int rlimit(int keep_open)
num_open.rlim_cur = FD_SETSIZE - SAFETY_MARGIN;
if (num_open.rlim_max > num_open.rlim_cur) {
sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d",
FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@ -409,7 +410,8 @@ static int rlimit(int keep_open)
rl.rlim_cur++) {
if ((fd[rl.rlim_cur] > 0) &&
((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) {
sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d",
FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@ -430,11 +432,13 @@ static int rlimit(int keep_open)
*/
if (!fopen_works()) {
sprintf(strbuff1, fmt, num_open.rlim_max);
sprintf(strbuff, "stdio fopen() fails with %s fds open()",
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff),
"stdio fopen() fails with %s fds open()",
strbuff1);
fprintf(stderr, "%s\n", msgbuff);
sprintf(strbuff, "stdio fopen() fails with lots of fds open()");
snprintf(strbuff, sizeof(strbuff),
"stdio fopen() fails with lots of fds open()");
store_errmsg(strbuff, 0);
close_file_descriptors();
free(memchunk);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -53,7 +53,7 @@ int test(char *URL)
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
sprintf(target_url, "%s%04i", URL, i + 1);
snprintf(target_url, sizeof(target_url), "%s%04i", URL, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl[i], CURLOPT_URL, target_url);
/* go verbose */

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2013, 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -58,9 +58,10 @@ static char msgbuff[256];
static void store_errmsg(const char *msg, int err)
{
if(!err)
sprintf(msgbuff, "%s", msg);
snprintf(msgbuff, sizeof(msgbuff), "%s", msg);
else
sprintf(msgbuff, "%s, errno %d, %s", msg, err, strerror(err));
snprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, err,
strerror(err));
}
static void close_file_descriptors(void)
@ -134,7 +135,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_cur);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "initial soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
@ -142,7 +143,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "initial hard limit: %s\n", strbuff);
/*
@ -194,7 +195,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_cur);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "current soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
@ -202,7 +203,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
sprintf(strbuff, fmt, rl.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "current hard limit: %s\n", strbuff);
} /* (rl.rlim_cur != rl.rlim_max) */
@ -232,7 +233,7 @@ static int rlimit(int keep_open)
nitems = 0x40000;
do {
num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems;
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
if(!memchunk) {
@ -275,8 +276,8 @@ static int rlimit(int keep_open)
/* verify that we won't overflow size_t in malloc() */
if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
sprintf(strbuff1, fmt, num_open.rlim_max);
sprintf(strbuff, "unable to allocate an array for %s "
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s "
"file descriptors, would overflow size_t", strbuff1);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
@ -287,7 +288,7 @@ static int rlimit(int keep_open)
/* allocate array for file descriptors */
do {
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "allocating array for %s file descriptors\n", strbuff);
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
if(!fd) {
@ -311,14 +312,14 @@ static int rlimit(int keep_open)
num_open.rlim_cur++)
fd[num_open.rlim_cur] = -1;
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "trying to open %s file descriptors\n", strbuff);
/* open a dummy descriptor */
fd[0] = open(DEV_NULL, O_RDONLY);
if(fd[0] < 0) {
sprintf(strbuff, "opening of %s failed", DEV_NULL);
snprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
store_errmsg(strbuff, ERRNO);
fprintf(stderr, "%s\n", msgbuff);
free(fd);
@ -339,19 +340,19 @@ static int rlimit(int keep_open)
fd[num_open.rlim_cur] = -1;
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "dup() attempt %s failed", strbuff1);
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
fprintf(stderr, "%s\n", strbuff);
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "fds system limit seems close to %s", strbuff1);
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", strbuff1);
fprintf(stderr, "%s\n", strbuff);
num_open.rlim_max = num_open.rlim_cur - SAFETY_MARGIN;
num_open.rlim_cur -= num_open.rlim_max;
sprintf(strbuff1, fmt, num_open.rlim_cur);
sprintf(strbuff, "closing %s file descriptors", strbuff1);
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
snprintf(strbuff, sizeof(strbuff), "closing %s file descriptors", strbuff1);
fprintf(stderr, "%s\n", strbuff);
for (num_open.rlim_cur = num_open.rlim_max;
@ -361,7 +362,7 @@ static int rlimit(int keep_open)
fd[num_open.rlim_cur] = -1;
}
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "shrinking array for %s file descriptors\n", strbuff);
/* we don't care if we can't shrink it */
@ -378,7 +379,7 @@ static int rlimit(int keep_open)
}
sprintf(strbuff, fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "%s file descriptors open\n", strbuff);
#if !defined(HAVE_POLL_FINE) && \
@ -398,7 +399,7 @@ static int rlimit(int keep_open)
num_open.rlim_cur = FD_SETSIZE - SAFETY_MARGIN;
if(num_open.rlim_max > num_open.rlim_cur) {
sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@ -412,7 +413,7 @@ static int rlimit(int keep_open)
rl.rlim_cur++) {
if((fd[rl.rlim_cur] > 0) &&
((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) {
sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@ -433,11 +434,11 @@ static int rlimit(int keep_open)
*/
if(!fopen_works()) {
sprintf(strbuff1, fmt, num_open.rlim_max);
sprintf(strbuff, "stdio fopen() fails with %s fds open()",
snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
snprintf(strbuff, sizeof(strbuff), "stdio fopen() fails with %s fds open()",
strbuff1);
fprintf(stderr, "%s\n", msgbuff);
sprintf(strbuff, "stdio fopen() fails with lots of fds open()");
snprintf(strbuff, sizeof(strbuff), "stdio fopen() fails with lots of fds open()");
store_errmsg(strbuff, 0);
close_file_descriptors();
free(memchunk);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -200,7 +200,7 @@ int test(char *URL)
if(test_argc < 4)
return 99;
sprintf(buffer, "Host: %s", HOST);
snprintf(buffer, sizeof(buffer), "Host: %s", HOST);
/* now add a custom Host: header */
headers = curl_slist_append(headers, buffer);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -74,7 +74,7 @@ int test(char *URL)
}
for (i = 0; i < NUM_HEADERS; i++) {
int len = sprintf(buf, "Header%d: ", i);
int len = snprintf(buf, sizeof(buf), "Header%d: ", i);
memset(&buf[len], 'A', SIZE_HEADERS);
buf[len + SIZE_HEADERS]=0; /* zero terminate */
hl = curl_slist_append(headerlist, buf);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -32,13 +32,14 @@ static CURLcode send_request(CURL *curl, const char *url, int seq,
long auth_scheme, const char *userpwd)
{
CURLcode res;
char* full_url = malloc(strlen(url) + 4 + 1);
size_t len = strlen(url) + 4 + 1;
char* full_url = malloc(len);
if (!full_url) {
fprintf(stderr, "Not enough memory for full url\n");
return CURLE_OUT_OF_MEMORY;
}
sprintf(full_url, "%s%04d", url, seq);
snprintf(full_url, len, "%s%04d", url, seq);
fprintf(stderr, "Sending new request %d to %s with credential %s "
"(auth %ld)\n", seq, full_url, userpwd, auth_scheme);
test_setopt(curl, CURLOPT_URL, full_url);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2012 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -103,7 +103,8 @@ int test(char *url)
int i, j;
int num_handles = 0;
enum HandleState state = ReadyForNewHandle;
char* full_url = malloc(strlen(url) + 4 + 1);
size_t urllen = strlen(url) + 4 + 1;
char* full_url = malloc(urllen);
start_test_timing();
@ -145,10 +146,10 @@ int test(char *url)
easy_init(easy[num_handles]);
if(num_handles % 3 == 2) {
sprintf(full_url, "%s0200", url);
snprintf(full_url, urllen, "%s0200", url);
easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
} else {
sprintf(full_url, "%s0100", url);
snprintf(full_url, urllen, "%s0100", url);
easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
easy_setopt(easy[num_handles], CURLOPT_FRESH_CONNECT, 1L);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -40,9 +40,7 @@
# include "select.h"
#endif
#define _MPRINTF_REPLACE
#include <curl/mprintf.h>
#include "curl_printf.h"
#define test_setopt(A,B,C) \
if((res = curl_easy_setopt((A),(B),(C))) != CURLE_OK) goto test_cleanup