mirror of
https://github.com/curl/curl.git
synced 2026-01-26 15:03:21 +00:00
curlx: replace sprintf with snprintf
To avoid using a deprecated function on Windows. Also: de-dupe `SNPRINTF` definition in curlx. Closes #19681
This commit is contained in:
parent
74bd3e2f98
commit
62683ad3f4
@ -50,6 +50,7 @@ LIB_CURLX_HFILES = \
|
||||
curlx/inet_pton.h \
|
||||
curlx/multibyte.h \
|
||||
curlx/nonblock.h \
|
||||
curlx/snprintf.h \
|
||||
curlx/strerr.h \
|
||||
curlx/strparse.h \
|
||||
curlx/timediff.h \
|
||||
|
||||
@ -95,8 +95,7 @@
|
||||
unlink(), etc. */
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), sprintf(),
|
||||
strcpy(),
|
||||
#define _CRT_SECURE_NO_WARNINGS /* for getenv(), gmtime(), strcpy(),
|
||||
in tests: localtime(), sscanf() */
|
||||
#endif
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#endif
|
||||
|
||||
#include "inet_ntop.h"
|
||||
#include "snprintf.h"
|
||||
|
||||
#define IN6ADDRSZ 16
|
||||
/* #define INADDRSZ 4 */
|
||||
@ -61,13 +62,12 @@ static char *inet_ntop4(const unsigned char *src, char *dst, size_t size)
|
||||
|
||||
DEBUGASSERT(size >= 16);
|
||||
|
||||
/* this sprintf() does not overflow the buffer. Avoids snprintf to work more
|
||||
widely. Avoids the msnprintf family to work as a curlx function. */
|
||||
(void)(sprintf)(tmp, "%d.%d.%d.%d",
|
||||
((int)((unsigned char)src[0])) & 0xff,
|
||||
((int)((unsigned char)src[1])) & 0xff,
|
||||
((int)((unsigned char)src[2])) & 0xff,
|
||||
((int)((unsigned char)src[3])) & 0xff);
|
||||
/* this snprintf() does not overflow the buffer. */
|
||||
SNPRINTF(tmp, sizeof(tmp), "%d.%d.%d.%d",
|
||||
((int)((unsigned char)src[0])) & 0xff,
|
||||
((int)((unsigned char)src[1])) & 0xff,
|
||||
((int)((unsigned char)src[2])) & 0xff,
|
||||
((int)((unsigned char)src[3])) & 0xff);
|
||||
|
||||
len = strlen(tmp);
|
||||
if(len == 0 || len >= size) {
|
||||
|
||||
36
lib/curlx/snprintf.h
Normal file
36
lib/curlx/snprintf.h
Normal file
@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 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
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* Raw snprintf() for curlx */
|
||||
|
||||
#ifdef WITHOUT_LIBCURL /* when built for the test servers */
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900) /* adjust for old MSVC */
|
||||
#define SNPRINTF _snprintf
|
||||
#else
|
||||
#define SNPRINTF snprintf
|
||||
#endif
|
||||
#else /* !WITHOUT_LIBCURL */
|
||||
#include <curl/mprintf.h>
|
||||
#define SNPRINTF curl_msnprintf
|
||||
#endif /* WITHOUT_LIBCURL */
|
||||
@ -34,21 +34,8 @@
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#ifndef WITHOUT_LIBCURL
|
||||
#include <curl/mprintf.h>
|
||||
#define SNPRINTF curl_msnprintf
|
||||
#else
|
||||
/* when built for the test servers */
|
||||
|
||||
/* adjust for old MSVC */
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define SNPRINTF _snprintf
|
||||
#else
|
||||
#define SNPRINTF snprintf
|
||||
#endif
|
||||
#endif /* !WITHOUT_LIBCURL */
|
||||
|
||||
#include "winapi.h"
|
||||
#include "snprintf.h"
|
||||
#include "strerr.h"
|
||||
/* The last 2 #include files should be in this order */
|
||||
#include "../curl_memory.h"
|
||||
|
||||
@ -29,20 +29,7 @@
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#include "winapi.h"
|
||||
|
||||
#ifndef WITHOUT_LIBCURL
|
||||
#include <curl/mprintf.h>
|
||||
#define SNPRINTF curl_msnprintf
|
||||
#else
|
||||
/* when built for the test servers */
|
||||
|
||||
/* adjust for old MSVC */
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define SNPRINTF _snprintf
|
||||
#else
|
||||
#define SNPRINTF snprintf
|
||||
#endif
|
||||
#endif /* !WITHOUT_LIBCURL */
|
||||
#include "snprintf.h"
|
||||
|
||||
/* This is a helper function for curlx_strerror that converts Windows API error
|
||||
* codes (GetLastError) to error messages.
|
||||
|
||||
@ -54,6 +54,7 @@ CURLX_HFILES = \
|
||||
../lib/curlx/fopen.h \
|
||||
../lib/curlx/multibyte.h \
|
||||
../lib/curlx/nonblock.h \
|
||||
../lib/curlx/snprintf.h \
|
||||
../lib/curlx/strerr.h \
|
||||
../lib/curlx/strparse.h \
|
||||
../lib/curlx/timediff.h \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user