spu2-x: windows: Fix incorrect use of scanf

Half width specifiers were not used, so scanf was writing ints into
bytes.

Note: Visual Studio 2013 doesn't support the hh format specifier.
This commit is contained in:
Jonathan Li 2015-07-23 19:01:15 +01:00
parent 150c53af0f
commit 25b9b24f77
1 changed files with 28 additions and 17 deletions

View File

@ -27,28 +27,39 @@ HRESULT GUIDFromString(const wchar_t *str, LPGUID guid)
{ {
// "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" // "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
struct T{ // this is a hack because for some reason sscanf writes too much :/ // VS2015 supports the hh format specifier (finally). VS2013 doesn't though,
GUID g; // so this will do for now.
int k; // << not used but still needed as of January 6th, 2011 u32 guid_u32;
} t; u16 guid_u16[2];
u16 guid_u8[8];
int r = swscanf_s(str,L"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", int r = swscanf_s(str,L"{%08x-%04hx-%04hx-%02hx%02hx-%02hx%02hx%02hx%02hx%02hx%02hx}",
&t.g.Data1, &guid_u32,
&t.g.Data2, &guid_u16[0],
&t.g.Data3, &guid_u16[1],
&t.g.Data4[0], &guid_u8[0],
&t.g.Data4[1], &guid_u8[1],
&t.g.Data4[2], &guid_u8[2],
&t.g.Data4[3], &guid_u8[3],
&t.g.Data4[4], &guid_u8[4],
&t.g.Data4[5], &guid_u8[5],
&t.g.Data4[6], &guid_u8[6],
&t.g.Data4[7] &guid_u8[7]
); );
if(r!=11) return -1; if(r!=11) return -1;
*guid = t.g; guid->Data1 = guid_u32;
guid->Data2 = guid_u16[0];
guid->Data3 = guid_u16[1];
guid->Data4[0] = (u8)guid_u8[0];
guid->Data4[1] = (u8)guid_u8[1];
guid->Data4[2] = (u8)guid_u8[2];
guid->Data4[3] = (u8)guid_u8[3];
guid->Data4[4] = (u8)guid_u8[4];
guid->Data4[5] = (u8)guid_u8[5];
guid->Data4[6] = (u8)guid_u8[6];
guid->Data4[7] = (u8)guid_u8[7];
return 0; return 0;
} }