[glib: 2/8] Fix signedness warnings in glib/gtimezone.c
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/8] Fix signedness warnings in glib/gtimezone.c
- Date: Wed, 20 Oct 2021 15:30:51 +0000 (UTC)
commit 6971f4f264cbf2b694442a0374cff30c0adea6e2
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date: Fri May 14 13:43:56 2021 +0200
Fix signedness warnings in glib/gtimezone.c
glib/gtimezone.c: In function 'rules_from_windows_time_zone':
glib/gtimezone.c:926:56: warning: comparison of integer expressions of different signedness: 'int' and
'DWORD' {aka 'long unsigned int'}
for (year = first, i = 0; *rules != NULL && year <= last; year++)
^~
glib/gtimezone.c:946:20: warning: comparison of integer expressions of different signedness: 'int' and
'DWORD' {aka 'long unsigned int'}
if (year > first && memcmp (®tzi_prev, ®tzi, sizeof regtzi) == 0)
^
glib/gtimezone.c: In function 'set_tz_name':
glib/gtimezone.c:1481:25: error: comparison of integer expressions of different signedness: 'int' and
'guint' {aka 'unsigned int'}
1481 | len = *pos - name_pos > size - 1 ? size - 1 : *pos - name_pos;
| ^
glib/gtimezone.c:1481:49: error: operand of '?:' changes signedness from 'int' to 'guint' {aka 'unsigned
int'} due to unsignedness of other operand
1481 | len = *pos - name_pos > size - 1 ? size - 1 : *pos - name_pos;
| ^~~~~~~~~~~~~~~
glib/gtimezone.c: In function 'rules_from_identifier':
glib/gtimezone.c:1553:25: warning: comparison of integer expressions of different signedness: 'int' and
'guint' {aka 'unsigned int'}
for (i = 0; i < rules_num - 1; i++)
^
glib/gtimezone.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/glib/gtimezone.c b/glib/gtimezone.c
index 4b4324222..2f65ab95e 100644
--- a/glib/gtimezone.c
+++ b/glib/gtimezone.c
@@ -157,7 +157,7 @@ typedef struct
*/
typedef struct
{
- gint start_year;
+ guint start_year;
gint32 std_offset;
gint32 dlt_offset;
TimeZoneDate dlt_start;
@@ -906,8 +906,7 @@ rules_from_windows_time_zone (const gchar *identifier,
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, subkey_dynamic_w, 0,
KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
{
- DWORD first, last;
- int year, i;
+ DWORD i, first, last, year;
wchar_t s[12];
size = sizeof first;
@@ -1458,6 +1457,8 @@ set_tz_name (gchar **pos, gchar *buffer, guint size)
gchar *name_pos = *pos;
guint len;
+ g_assert (size != 0);
+
if (quoted)
{
name_pos++;
@@ -1479,7 +1480,7 @@ set_tz_name (gchar **pos, gchar *buffer, guint size)
memset (buffer, 0, size);
/* name_pos isn't 0-terminated, so we have to limit the length expressly */
- len = *pos - name_pos > size - 1 ? size - 1 : *pos - name_pos;
+ len = (guint) (*pos - name_pos) > size - 1 ? size - 1 : (guint) (*pos - name_pos);
strncpy (buffer, name_pos, len);
*pos += quoted;
return TRUE;
@@ -1542,8 +1543,7 @@ rules_from_identifier (const gchar *identifier,
#ifdef G_OS_WIN32
/* Windows allows us to use the US DST boundaries if they're not given */
{
- int i;
- guint rules_num = 0;
+ guint i, rules_num = 0;
/* Use US rules, Windows' default is Pacific Standard Time */
if ((rules_num = rules_from_windows_time_zone ("Pacific Standard Time",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]