From c92d449f7a055769f518a809487f97d8272c4e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 6 Aug 2022 16:59:56 +0200 Subject: Update Hungarian notation for buffer sizes. For string lengths EXCLUDING NUL, I use len, whereas cb and cch are used for string lengths INCLUDING NUL. cb = byte count = sizeof(a) = narrow string length cch = character count = sizeof(a)/sizeof(*a) = string length cb and cch are equivalent for narrow strings. I prefer cch. --- c/wcharptr.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'c/wcharptr.cpp') diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp index d1332d5..f36c620 100644 --- a/c/wcharptr.cpp +++ b/c/wcharptr.cpp @@ -6,10 +6,10 @@ WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) { - int cbMultiByte = strlen(src)+1; - int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, nullptr, 0); - wchar_t* dst = new wchar_t[cchWideChar]; - if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) { + int cchNarrow = strlen(src)+1; + int cchWide = MultiByteToWideChar(cp, 0, src, cchNarrow, nullptr, 0); + wchar_t* dst = new wchar_t[cchWide]; + if (!MultiByteToWideChar(cp, 0, src, cchNarrow, dst, cchWide)) { delete dst; throw Win32Error(); } @@ -18,9 +18,9 @@ WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) WcharPtr WcharPtr::Copy(const wchar_t* const src) { - const int cb = wcslen(src)+1; - wchar_t* dst = new wchar_t[cb]; - memcpy(dst, src, cb*sizeof(wchar_t)); + const int cch = wcslen(src)+1; + wchar_t* dst = new wchar_t[cch]; + memcpy(dst, src, cch*sizeof(wchar_t)); return dst; } -- cgit v1.2.3