mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2024-11-27 21:54:18 +01:00
vswprintf causes Purify to fail (#145). r=darin
http://groups.google.com/group/google-breakpad-dev/browse_thread/thread/88e18d9fac4eee22 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@135 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
3479e850c5
commit
aec44489da
@ -475,9 +475,9 @@ void ExceptionHandler::UpdateNextID() {
|
||||
next_minidump_id_c_ = next_minidump_id_.c_str();
|
||||
|
||||
wchar_t minidump_path[MAX_PATH];
|
||||
WindowsStringUtils::safe_swprintf(minidump_path, MAX_PATH, L"%s\\%s.dmp",
|
||||
dump_path_c_,
|
||||
next_minidump_id_c_);
|
||||
swprintf(minidump_path, MAX_PATH, L"%s\\%s.dmp",
|
||||
dump_path_c_, next_minidump_id_c_);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(minidump_path, MAX_PATH);
|
||||
next_minidump_path_ = minidump_path;
|
||||
next_minidump_path_c_ = next_minidump_path_.c_str();
|
||||
}
|
||||
|
@ -42,26 +42,30 @@ namespace google_breakpad {
|
||||
// static
|
||||
wstring GUIDString::GUIDToWString(GUID *guid) {
|
||||
wchar_t guid_string[37];
|
||||
WindowsStringUtils::safe_swprintf(
|
||||
swprintf(
|
||||
guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
|
||||
L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
guid->Data1, guid->Data2, guid->Data3,
|
||||
guid->Data4[0], guid->Data4[1], guid->Data4[2],
|
||||
guid->Data4[3], guid->Data4[4], guid->Data4[5],
|
||||
guid->Data4[6], guid->Data4[7]);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(guid_string,
|
||||
sizeof(guid_string) / sizeof(guid_string[0]));
|
||||
return wstring(guid_string);
|
||||
}
|
||||
|
||||
// static
|
||||
wstring GUIDString::GUIDToSymbolServerWString(GUID *guid) {
|
||||
wchar_t guid_string[33];
|
||||
WindowsStringUtils::safe_swprintf(
|
||||
swprintf(
|
||||
guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
|
||||
L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
guid->Data1, guid->Data2, guid->Data3,
|
||||
guid->Data4[0], guid->Data4[1], guid->Data4[2],
|
||||
guid->Data4[3], guid->Data4[4], guid->Data4[5],
|
||||
guid->Data4[6], guid->Data4[7]);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(guid_string,
|
||||
sizeof(guid_string) / sizeof(guid_string[0]));
|
||||
return wstring(guid_string);
|
||||
}
|
||||
|
||||
|
@ -213,8 +213,8 @@ wstring HTTPUpload::GenerateMultipartBoundary() {
|
||||
int r1 = rand();
|
||||
|
||||
wchar_t temp[kBoundaryLength];
|
||||
WindowsStringUtils::safe_swprintf(temp, kBoundaryLength, L"%s%08X%08X",
|
||||
kBoundaryPrefix, r0, r1);
|
||||
swprintf(temp, kBoundaryLength, L"%s%08X%08X", kBoundaryPrefix, r0, r1);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(temp, kBoundaryLength);
|
||||
return wstring(temp);
|
||||
}
|
||||
|
||||
|
@ -723,9 +723,10 @@ bool PDBSourceLineWriter::GetModuleInfo(PDBModuleInfo *info) {
|
||||
// Use the same format that the MS symbol server uses in filesystem
|
||||
// hierarchies.
|
||||
wchar_t age_string[9];
|
||||
WindowsStringUtils::safe_swprintf(
|
||||
age_string, sizeof(age_string) / sizeof(age_string[0]),
|
||||
L"%x", age);
|
||||
swprintf(age_string, sizeof(age_string) / sizeof(age_string[0]),
|
||||
L"%x", age);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(age_string,
|
||||
sizeof(age_string) / sizeof(age_string[0]));
|
||||
|
||||
info->debug_identifier = GUIDString::GUIDToSymbolServerWString(&guid);
|
||||
info->debug_identifier.append(age_string);
|
||||
@ -738,10 +739,12 @@ bool PDBSourceLineWriter::GetModuleInfo(PDBModuleInfo *info) {
|
||||
// Use the same format that the MS symbol server uses in filesystem
|
||||
// hierarchies.
|
||||
wchar_t identifier_string[17];
|
||||
WindowsStringUtils::safe_swprintf(
|
||||
identifier_string,
|
||||
sizeof(identifier_string) / sizeof(identifier_string[0]),
|
||||
L"%08X%x", signature, age);
|
||||
swprintf(identifier_string,
|
||||
sizeof(identifier_string) / sizeof(identifier_string[0]),
|
||||
L"%08X%x", signature, age);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(identifier_string,
|
||||
sizeof(identifier_string) /
|
||||
sizeof(identifier_string[0]));
|
||||
info->debug_identifier = identifier_string;
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,19 @@
|
||||
#define WIN_STRING_FORMAT_LL "I64"
|
||||
#endif // MSC_VER >= 1400
|
||||
|
||||
// When using swprintf, call GB_WSU_SWPRINTF_TERMINATE afterwards using the
|
||||
// first two arguments to swprintf. This will ensure that the buffer is
|
||||
// 0-terminated. MSVC8's swprintf always 0-terminates the buffer, so the
|
||||
// macro is a no-op. This is done in a macro rather than a function
|
||||
// because the function approach relies on vswprintf, which is incompatible
|
||||
// with some analysis tools.
|
||||
#if _MSC_VER >= 1400 // MSVC 2005/8
|
||||
#define GB_WSU_SAFE_SWPRINTF_TERMINATE(buffer, count);
|
||||
#else // _MSC_VER >= 1400
|
||||
#define GB_WSU_SAFE_SWPRINTF_TERMINATE(buffer, count); \
|
||||
(buffer)[(count) - 1] = L'\0';
|
||||
#endif // _MSC_VER >= 1400
|
||||
|
||||
namespace google_breakpad {
|
||||
|
||||
using std::string;
|
||||
@ -56,10 +69,6 @@ using std::wstring;
|
||||
|
||||
class WindowsStringUtils {
|
||||
public:
|
||||
// Equivalent to MSVC8's swprintf, which always 0-terminates buffer.
|
||||
static void safe_swprintf(wchar_t *buffer, size_t count,
|
||||
const wchar_t *format, ...);
|
||||
|
||||
// Roughly equivalent to MSVC8's wcscpy_s, except pre-MSVC8, this does
|
||||
// not fail if source is longer than destination_size. The destination
|
||||
// buffer is always 0-terminated.
|
||||
@ -89,21 +98,6 @@ class WindowsStringUtils {
|
||||
void operator=(const WindowsStringUtils&);
|
||||
};
|
||||
|
||||
// static
|
||||
inline void WindowsStringUtils::safe_swprintf(wchar_t *buffer, size_t count,
|
||||
const wchar_t *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vswprintf(buffer, count, format, args);
|
||||
|
||||
#if _MSC_VER < 1400 // MSVC 2005/8
|
||||
// Pre-MSVC 2005/8 doesn't 0-terminate the buffer if the formatted string
|
||||
// is larger than the buffer. Ensure that the string is 0-terminated.
|
||||
if (buffer && count)
|
||||
buffer[count - 1] = 0;
|
||||
#endif // _MSC_VER < 1400
|
||||
}
|
||||
|
||||
// static
|
||||
inline void WindowsStringUtils::safe_wcscpy(wchar_t *destination,
|
||||
size_t destination_size,
|
||||
|
@ -91,13 +91,14 @@ static bool GetFileVersionString(const wchar_t *filename, wstring *version) {
|
||||
wchar_t ver_string[24];
|
||||
VS_FIXEDFILEINFO *file_info =
|
||||
reinterpret_cast<VS_FIXEDFILEINFO*>(file_info_buffer);
|
||||
WindowsStringUtils::safe_swprintf(
|
||||
ver_string, sizeof(ver_string) / sizeof(ver_string[0]),
|
||||
L"%d.%d.%d.%d",
|
||||
file_info->dwFileVersionMS >> 16,
|
||||
file_info->dwFileVersionMS & 0xffff,
|
||||
file_info->dwFileVersionLS >> 16,
|
||||
file_info->dwFileVersionLS & 0xffff);
|
||||
swprintf(ver_string, sizeof(ver_string) / sizeof(ver_string[0]),
|
||||
L"%d.%d.%d.%d",
|
||||
file_info->dwFileVersionMS >> 16,
|
||||
file_info->dwFileVersionMS & 0xffff,
|
||||
file_info->dwFileVersionLS >> 16,
|
||||
file_info->dwFileVersionLS & 0xffff);
|
||||
GB_WSU_SAFE_SWPRINTF_TERMINATE(ver_string,
|
||||
sizeof(ver_string) / sizeof(ver_string[0]));
|
||||
*version = ver_string;
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user