From 46789bd14d5fc7448dbd1b68138a8b08964353bc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 30 Nov 2014 13:03:10 +0000 Subject: safe lstr* replacements: mir_strlen, mir_wstrlen, mir_strcpy, mir_wstrcpy, mir_strncpy, mir_wstrncpy, mir_strcat, mir_wstrcat, mir_strncat, mir_wstrncat git-svn-id: http://svn.miranda-ng.org/main/trunk@11171 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/mir_core.def | 10 ++++ src/mir_core/utils.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 137 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def index cf18d01709..b0b369f320 100644 --- a/src/mir_core/mir_core.def +++ b/src/mir_core/mir_core.def @@ -266,3 +266,13 @@ PathIsAbsolute @263 PathIsAbsoluteW @264 db_mc_notifyDefChange @265 db_mc_tryMeta @266 +mir_strlen @267 +mir_wstrlen @268 +mir_strcpy @269 +mir_wstrcpy @270 +mir_strncpy @271 +mir_wstrncpy @272 +mir_strcat @273 +mir_wstrcat @274 +mir_strncat @275 +mir_wstrncat @276 diff --git a/src/mir_core/utils.cpp b/src/mir_core/utils.cpp index 69ad5de18e..28d48f7f33 100644 --- a/src/mir_core/utils.cpp +++ b/src/mir_core/utils.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" -MIR_CORE_DLL(char*) replaceStr( char* &dest, const char *src) +MIR_CORE_DLL(char*) replaceStr(char* &dest, const char *src) { if (dest != NULL) mir_free(dest); @@ -32,7 +32,7 @@ MIR_CORE_DLL(char*) replaceStr( char* &dest, const char *src) return dest = (src != NULL) ? mir_strdup(src) : NULL; } -MIR_CORE_DLL(WCHAR*) replaceStrW( WCHAR* &dest, const WCHAR *src) +MIR_CORE_DLL(WCHAR*) replaceStrW(WCHAR* &dest, const WCHAR *src) { if (dest != NULL) mir_free(dest); @@ -175,7 +175,7 @@ MIR_CORE_DLL(int) wildcmpw(const WCHAR *name, const WCHAR *mask) } if (*mask != '*') return FALSE; for (;; mask++, name++) { - while(*mask == '*') { + while (*mask == '*') { last = mask++; if (*mask == '\0') return ((BOOL)!*mask); /* true */ } @@ -198,12 +198,12 @@ MIR_CORE_DLL(int) wildcmpi(const char *name, const char *mask) } if (*mask != '*') return FALSE; for (;; mask++, name++) { - while(*mask == '*') { + while (*mask == '*') { last = mask++; if (*mask == '\0') return ((BOOL)!*mask); /* true */ } if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */ - if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last; + if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last; } } @@ -219,12 +219,12 @@ MIR_CORE_DLL(int) wildcmpiw(const WCHAR *name, const WCHAR *mask) } if (*mask != '*') return FALSE; for (;; mask++, name++) { - while(*mask == '*') { + while (*mask == '*') { last = mask++; if (*mask == '\0') return ((BOOL)!*mask); /* true */ } if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */ - if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last; + if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last; } } @@ -237,7 +237,7 @@ MIR_CORE_DLL(char*) bin2hex(const void *pData, size_t len, char *dest) const BYTE *p = (const BYTE*)pData; char *d = dest; - for (size_t i=0; i < len; i++, p++) { + for (size_t i = 0; i < len; i++, p++) { *d++ = szHexTable[*p >> 4]; *d++ = szHexTable[*p & 0x0F]; } @@ -251,7 +251,7 @@ MIR_CORE_DLL(WCHAR*) bin2hexW(const void *pData, size_t len, WCHAR *dest) const BYTE *p = (const BYTE*)pData; WCHAR *d = dest; - for (size_t i=0; i < len; i++, p++) { + for (size_t i = 0; i < len; i++, p++) { *d++ = szHexTable[*p >> 4]; *d++ = szHexTable[*p & 0x0F]; } @@ -259,3 +259,121 @@ MIR_CORE_DLL(WCHAR*) bin2hexW(const void *pData, size_t len, WCHAR *dest) return dest; } + +///////////////////////////////////////////////////////////////////////////////////////// + +#pragma intrinsic(strlen, strcpy, strcat, wcslen, wcscpy, wcscat) + +MIR_CORE_DLL(size_t) mir_strlen(const char *p) +{ + return (p) ? strlen(p) : 0; +} + +MIR_CORE_DLL(size_t) mir_wstrlen(const wchar_t *p) +{ + return (p) ? wcslen(p) : 0; +} + +MIR_CORE_DLL(char*) mir_strcpy(char *dest, const char *src) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return strcpy(dest, src); +} + +MIR_CORE_DLL(wchar_t*) mir_wstrcpy(wchar_t *dest, const wchar_t *src) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return wcscpy(dest, src); +} + +MIR_CORE_DLL(char*) mir_strncpy(char *dest, const char *src, size_t len) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return strncpy(dest, src, len); +} + +MIR_CORE_DLL(wchar_t*) mir_wstrncpy(wchar_t *dest, const wchar_t *src, size_t len) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return wcsncpy(dest, src, len); +} + +MIR_CORE_DLL(char*) mir_strcat(char *dest, const char *src) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return strcat(dest, src); +} + +MIR_CORE_DLL(wchar_t*) mir_wstrcat(wchar_t *dest, const wchar_t *src) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return wcscat(dest, src); +} + +MIR_CORE_DLL(char*) mir_strncat(char *dest, const char *src, size_t len) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return strncat(dest, src, len); +} + +MIR_CORE_DLL(wchar_t*) mir_wstrncat(wchar_t *dest, const wchar_t *src, size_t len) +{ + if (dest == NULL) + return NULL; + + if (src == NULL) { + *dest = 0; + return dest; + } + + return wcsncat(dest, src, len); +} -- cgit v1.2.3