Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: src/utils/win/SkDWrite.cpp

Issue 500113002: Require length in sk_wchar_to_string. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/win/SkDWrite.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/win/SkDWrite.cpp
diff --git a/src/utils/win/SkDWrite.cpp b/src/utils/win/SkDWrite.cpp
index 87826b5194e4e52a8a540efb3df10ced65a7c009..7801059187c0907cba9dac5b01afd6df2f7bd8b1 100644
--- a/src/utils/win/SkDWrite.cpp
+++ b/src/utils/win/SkDWrite.cpp
@@ -67,23 +67,19 @@ HRESULT sk_cstring_to_wchar(const char* skname, SkSMallocWCHAR* name) {
}
/** Converts a WCHAR string to a utf8 string. */
-HRESULT sk_wchar_to_skstring(WCHAR* name, SkString* skname) {
- int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, NULL, 0, NULL, NULL);
+HRESULT sk_wchar_to_skstring(WCHAR* name, int nameLen, SkString* skname) {
+ int len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, NULL, 0, NULL, NULL);
if (0 == len) {
+ if (nameLen <= 0) {
+ skname->reset();
+ return S_OK;
+ }
HRM(HRESULT_FROM_WIN32(GetLastError()),
"Could not get length for utf-8 to wchar conversion.");
}
- skname->resize(len - 1);
-
- // TODO: remove after https://code.google.com/p/skia/issues/detail?id=1989 is fixed.
- // If we resize to 0 then the skname points to gEmptyRec (the unique empty SkString::Rec).
- // gEmptyRec is static const and on Windows this means the value is in a read only page.
- // Writing to it in the following call to WideCharToMultiByte will cause an access violation.
- if (1 == len) {
- return S_OK;
- }
+ skname->resize(len);
- len = WideCharToMultiByte(CP_UTF8, 0, name, -1, skname->writable_str(), len, NULL, NULL);
+ len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, skname->writable_str(), len, NULL, NULL);
if (0 == len) {
HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wchar.");
}
@@ -105,14 +101,13 @@ void sk_get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* preferedL
}
}
- UINT32 nameLength;
- HRVM(names->GetStringLength(nameIndex, &nameLength), "Could not get name length.");
- nameLength += 1;
+ UINT32 nameLen;
+ HRVM(names->GetStringLength(nameIndex, &nameLen), "Could not get name length.");
- SkSMallocWCHAR name(nameLength);
- HRVM(names->GetString(nameIndex, name.get(), nameLength), "Could not get string.");
+ SkSMallocWCHAR name(nameLen+1);
+ HRVM(names->GetString(nameIndex, name.get(), nameLen+1), "Could not get string.");
- HRV(sk_wchar_to_skstring(name.get(), skname));
+ HRV(sk_wchar_to_skstring(name.get(), nameLen, skname));
}
HRESULT SkGetGetUserDefaultLocaleNameProc(SkGetUserDefaultLocaleNameProc* proc) {
« no previous file with comments | « src/utils/win/SkDWrite.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698