mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-10 23:00:07 +02:00
gwin32: Use gsize internally in g_wcsdup()
This allows it to handle strings up to length `G_MAXSIZE` — previously it would overflow with such strings. Update the several copies of it identically. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #2319
This commit is contained in:
parent
41d5eedad4
commit
9acebef777
@ -17,10 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static gssize
|
static gsize
|
||||||
g_utf16_len (const gunichar2 *str)
|
g_utf16_len (const gunichar2 *str)
|
||||||
{
|
{
|
||||||
gssize result;
|
gsize result;
|
||||||
|
|
||||||
for (result = 0; str[0] != 0; str++, result++)
|
for (result = 0; str[0] != 0; str++, result++)
|
||||||
;
|
;
|
||||||
@ -31,17 +31,20 @@ g_utf16_len (const gunichar2 *str)
|
|||||||
static gunichar2 *
|
static gunichar2 *
|
||||||
g_wcsdup (const gunichar2 *str, gssize str_len)
|
g_wcsdup (const gunichar2 *str, gssize str_len)
|
||||||
{
|
{
|
||||||
gssize str_size;
|
gsize str_len_unsigned;
|
||||||
|
gsize str_size;
|
||||||
|
|
||||||
g_return_val_if_fail (str != NULL, NULL);
|
g_return_val_if_fail (str != NULL, NULL);
|
||||||
|
|
||||||
if (str_len == -1)
|
if (str_len < 0)
|
||||||
str_len = g_utf16_len (str);
|
str_len_unsigned = g_utf16_len (str);
|
||||||
|
else
|
||||||
|
str_len_unsigned = (gsize) str_len;
|
||||||
|
|
||||||
g_assert (str_len <= G_MAXSIZE / sizeof (gunichar2) - 1);
|
g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1);
|
||||||
str_size = (str_len + 1) * sizeof (gunichar2);
|
str_size = (str_len_unsigned + 1) * sizeof (gunichar2);
|
||||||
|
|
||||||
return g_memdup (str, str_size);
|
return g_memdup2 (str, str_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const gunichar2 *
|
static const gunichar2 *
|
||||||
|
@ -62,10 +62,10 @@ typedef HRESULT (STDAPICALLTYPE *CreateXmlReader_func)(REFIID riid, void **ppvOb
|
|||||||
#define sax_CreateXmlReader sax->CreateXmlReader
|
#define sax_CreateXmlReader sax->CreateXmlReader
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static gssize
|
static gsize
|
||||||
g_utf16_len (const gunichar2 *str)
|
g_utf16_len (const gunichar2 *str)
|
||||||
{
|
{
|
||||||
gssize result;
|
gsize result;
|
||||||
|
|
||||||
for (result = 0; str[0] != 0; str++, result++)
|
for (result = 0; str[0] != 0; str++, result++)
|
||||||
;
|
;
|
||||||
@ -76,17 +76,20 @@ g_utf16_len (const gunichar2 *str)
|
|||||||
static gunichar2 *
|
static gunichar2 *
|
||||||
g_wcsdup (const gunichar2 *str, gssize str_len)
|
g_wcsdup (const gunichar2 *str, gssize str_len)
|
||||||
{
|
{
|
||||||
gssize str_size;
|
gsize str_len_unsigned;
|
||||||
|
gsize str_size;
|
||||||
|
|
||||||
g_return_val_if_fail (str != NULL, NULL);
|
g_return_val_if_fail (str != NULL, NULL);
|
||||||
|
|
||||||
if (str_len == -1)
|
if (str_len < 0)
|
||||||
str_len = g_utf16_len (str);
|
str_len_unsigned = g_utf16_len (str);
|
||||||
|
else
|
||||||
|
str_len_unsigned = (gsize) str_len;
|
||||||
|
|
||||||
g_assert (str_len <= G_MAXSIZE / sizeof (gunichar2) - 1);
|
g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1);
|
||||||
str_size = (str_len + 1) * sizeof (gunichar2);
|
str_size = (str_len_unsigned + 1) * sizeof (gunichar2);
|
||||||
|
|
||||||
return g_memdup (str, str_size);
|
return g_memdup2 (str, str_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
|
@ -125,16 +125,34 @@ typedef enum
|
|||||||
G_WIN32_REGISTRY_UPDATED_PATH = 1,
|
G_WIN32_REGISTRY_UPDATED_PATH = 1,
|
||||||
} GWin32RegistryKeyUpdateFlag;
|
} GWin32RegistryKeyUpdateFlag;
|
||||||
|
|
||||||
static gunichar2 *
|
static gsize
|
||||||
g_wcsdup (const gunichar2 *str,
|
g_utf16_len (const gunichar2 *str)
|
||||||
gssize str_size)
|
|
||||||
{
|
{
|
||||||
if (str_size == -1)
|
gsize result;
|
||||||
{
|
|
||||||
str_size = wcslen (str) + 1;
|
for (result = 0; str[0] != 0; str++, result++)
|
||||||
str_size *= sizeof (gunichar2);
|
;
|
||||||
}
|
|
||||||
return g_memdup (str, str_size);
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gunichar2 *
|
||||||
|
g_wcsdup (const gunichar2 *str, gssize str_len)
|
||||||
|
{
|
||||||
|
gsize str_len_unsigned;
|
||||||
|
gsize str_size;
|
||||||
|
|
||||||
|
g_return_val_if_fail (str != NULL, NULL);
|
||||||
|
|
||||||
|
if (str_len < 0)
|
||||||
|
str_len_unsigned = g_utf16_len (str);
|
||||||
|
else
|
||||||
|
str_len_unsigned = (gsize) str_len;
|
||||||
|
|
||||||
|
g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1);
|
||||||
|
str_size = (str_len_unsigned + 1) * sizeof (gunichar2);
|
||||||
|
|
||||||
|
return g_memdup2 (str, str_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user