mirror of
https://github.com/curl/curl.git
synced 2026-06-20 10:45:38 +03:00
curlx: move fopen and multibyte to curlx_malloc
Let's see what fallout this makes
This commit is contained in:
parent
c421c3e325
commit
2613bd922a
3 changed files with 18 additions and 28 deletions
|
|
@ -100,8 +100,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
|
|||
goto cleanup;
|
||||
if(!needed || needed >= max_path_len)
|
||||
goto cleanup;
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
ibuf = malloc(needed * sizeof(wchar_t));
|
||||
ibuf = curlx_malloc(needed * sizeof(wchar_t));
|
||||
if(!ibuf)
|
||||
goto cleanup;
|
||||
if(mbstowcs_s(&count, ibuf, needed, in, needed - 1))
|
||||
|
|
@ -122,8 +121,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
|
|||
/* skip paths that are not excessive and do not need modification */
|
||||
if(needed <= MAX_PATH)
|
||||
goto cleanup;
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
fbuf = malloc(needed * sizeof(wchar_t));
|
||||
fbuf = curlx_malloc(needed * sizeof(wchar_t));
|
||||
if(!fbuf)
|
||||
goto cleanup;
|
||||
count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL);
|
||||
|
|
@ -156,8 +154,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
|
|||
if(needed > max_path_len)
|
||||
goto cleanup;
|
||||
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
temp = malloc(needed * sizeof(wchar_t));
|
||||
temp = curlx_malloc(needed * sizeof(wchar_t));
|
||||
if(!temp)
|
||||
goto cleanup;
|
||||
|
||||
|
|
@ -178,8 +175,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
|
|||
if(needed > max_path_len)
|
||||
goto cleanup;
|
||||
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
temp = malloc(needed * sizeof(wchar_t));
|
||||
temp = curlx_malloc(needed * sizeof(wchar_t));
|
||||
if(!temp)
|
||||
goto cleanup;
|
||||
|
||||
|
|
@ -206,8 +202,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
|
|||
goto cleanup;
|
||||
if(!needed || needed >= max_path_len)
|
||||
goto cleanup;
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
obuf = malloc(needed);
|
||||
obuf = curlx_malloc(needed);
|
||||
if(!obuf)
|
||||
goto cleanup;
|
||||
if(wcstombs_s(&count, obuf, needed, fbuf, needed - 1))
|
||||
|
|
@ -222,12 +217,10 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
|
|||
#endif
|
||||
|
||||
cleanup:
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
free(fbuf);
|
||||
curlx_free(fbuf);
|
||||
#ifndef _UNICODE
|
||||
/* !checksrc! disable BANNEDFUNC 2 */
|
||||
free(ibuf);
|
||||
free(obuf);
|
||||
curlx_free(ibuf);
|
||||
curlx_free(obuf);
|
||||
#endif
|
||||
return *out ? true : false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,13 +45,11 @@ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8)
|
|||
int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
|
||||
str_utf8, -1, NULL, 0);
|
||||
if(str_w_len > 0) {
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
str_w = malloc(str_w_len * sizeof(wchar_t));
|
||||
str_w = curlx_malloc(str_w_len * sizeof(wchar_t));
|
||||
if(str_w) {
|
||||
if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
|
||||
str_w_len) == 0) {
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
free(str_w);
|
||||
curlx_free(str_w);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -69,13 +67,11 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
|
|||
int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
|
||||
NULL, 0, NULL, NULL);
|
||||
if(bytes > 0) {
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
str_utf8 = malloc(bytes);
|
||||
str_utf8 = curlx_malloc(bytes);
|
||||
if(str_utf8) {
|
||||
if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
|
||||
NULL, NULL) == 0) {
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
free(str_utf8);
|
||||
curlx_free(str_utf8);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,8 @@
|
|||
#ifdef CURLDEBUG
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "urldata.h"
|
||||
#include "curl_threads.h"
|
||||
#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW(), CURLX_FREOPEN_LOW() */
|
||||
|
||||
#ifdef USE_BACKTRACE
|
||||
#include "backtrace.h"
|
||||
|
|
@ -128,7 +126,8 @@ void curl_dbg_memdebug(const char *logname)
|
|||
{
|
||||
if(!curl_dbg_logfile) {
|
||||
if(logname && *logname)
|
||||
curl_dbg_logfile = CURLX_FOPEN_LOW(logname, FOPEN_WRITETEXT);
|
||||
/* !checksrc! disable BANNEDFUNC 1 - accept fopen() */
|
||||
curl_dbg_logfile = fopen(logname, "wt");
|
||||
#ifdef MEMDEBUG_LOG_SYNC
|
||||
/* Flush the log file after every line so the log is not lost in a crash */
|
||||
if(curl_dbg_logfile)
|
||||
|
|
@ -478,7 +477,8 @@ ALLOC_FUNC
|
|||
FILE *curl_dbg_fopen(const char *file, const char *mode,
|
||||
int line, const char *source)
|
||||
{
|
||||
FILE *res = CURLX_FOPEN_LOW(file, mode);
|
||||
/* !checksrc! disable BANNEDFUNC 1 use fopen here */
|
||||
FILE *res = fopen(file, mode);
|
||||
if(source)
|
||||
curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
|
||||
source, line, file, mode, (void *)res);
|
||||
|
|
@ -490,7 +490,8 @@ ALLOC_FUNC
|
|||
FILE *curl_dbg_freopen(const char *file, const char *mode, FILE *fh,
|
||||
int line, const char *source)
|
||||
{
|
||||
FILE *res = CURLX_FREOPEN_LOW(file, mode, fh);
|
||||
/* !checksrc! disable BANNEDFUNC 1 - accept freopen() */
|
||||
FILE *res = freopen(file, mode, fh);
|
||||
if(source)
|
||||
curl_dbg_log("FILE %s:%d freopen(\"%s\",\"%s\",%p) = %p\n",
|
||||
source, line, file, mode, (void *)fh, (void *)res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue