aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest/lib518.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2016-04-01 10:14:06 +0200
committerDaniel Stenberg <daniel@haxx.se>2016-04-01 10:46:36 +0200
commit55452ebdff47f98bf3cc383f1dfc3623fcaefefd (patch)
treed17d3be8fd9482658f07ef6b4532da9502499cf0 /tests/libtest/lib518.c
parent7218b52c49aeb1452d1fb94b394b3de2da938f17 (diff)
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.
Diffstat (limited to 'tests/libtest/lib518.c')
-rw-r--r--tests/libtest/lib518.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c
index 94343f67c..3e6c492dc 100644
--- a/tests/libtest/lib518.c
+++ b/tests/libtest/lib518.c
@@ -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,10 +234,10 @@ 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",
- strbuff1, strbuff2);
+ 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);
return -4;
@@ -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,9 +286,9 @@ 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 "
- "file descriptors, would overflow size_t", strbuff1);
+ 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);
free(memchunk);
@@ -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,20 +345,20 @@ 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",
- strbuff2, strbuff1);
+ 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()",
- strbuff1);
+ 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);