Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Guard against GetDateFormatW() or GetTimeFormatW() returning zero.
Browse files Browse the repository at this point in the history
2007-02-17  Tor Lillqvist  <tml@novell.com>

	* glib/gdate.c (win32_strftime_helper): Guard against
	GetDateFormatW() or GetTimeFormatW() returning zero.


svn path=/branches/glib-2-12/; revision=5340
  • Loading branch information
Tor Lillqvist authored and Tor Lillqvist committed Feb 17, 2007
1 parent 6e15aa0 commit 080a4c9
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions glib/gdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,14 +1524,20 @@ win32_strftime_helper (const GDate *d,
break;
case 'c':
n = GetDateFormatW (lcid, 0, &systemtime, NULL, NULL, 0);
g_array_set_size (result, result->len + n);
GetDateFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
if (n > 0)
{
g_array_set_size (result, result->len + n);
GetDateFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
g_array_append_vals (result, L" ", 1);
n = GetTimeFormatW (lcid, 0, &systemtime, NULL, NULL, 0);
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
if (n > 0)
{
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
break;
case 'C':
g_array_append_vals (result, digits + systemtime.wYear/1000, 1);
Expand Down Expand Up @@ -1609,9 +1615,12 @@ win32_strftime_helper (const GDate *d,
break;
case 'p':
n = GetTimeFormatW (lcid, 0, &systemtime, L"tt", NULL, 0);
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, L"tt", ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
if (n > 0)
{
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, L"tt", ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
break;
case 'r':
/* This is a rather odd format. Hard to say what to do.
Expand All @@ -1636,9 +1645,12 @@ win32_strftime_helper (const GDate *d,
g_array_append_vals (result, L" ", 1);
#endif
n = GetTimeFormatW (lcid, 0, &systemtime, L"tt", NULL, 0);
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, L"tt", ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
if (n > 0)
{
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, L"tt", ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
break;
case 'R':
#if 1
Expand Down Expand Up @@ -1702,15 +1714,21 @@ win32_strftime_helper (const GDate *d,
break;
case 'x':
n = GetDateFormatW (lcid, 0, &systemtime, NULL, NULL, 0);
g_array_set_size (result, result->len + n);
GetDateFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
if (n > 0)
{
g_array_set_size (result, result->len + n);
GetDateFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
break;
case 'X':
n = GetTimeFormatW (lcid, 0, &systemtime, NULL, NULL, 0);
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
if (n > 0)
{
g_array_set_size (result, result->len + n);
GetTimeFormatW (lcid, 0, &systemtime, NULL, ((wchar_t *) result->data) + result->len - n, n);
g_array_set_size (result, result->len - 1);
}
break;
case 'y':
g_array_append_vals (result, digits + (systemtime.wYear/10)%10, 1);
Expand Down

0 comments on commit 080a4c9

Please sign in to comment.