Skip to contentSkip to conversation

dhcp-util: fix GCC 10 warning

PATCH Applied James Prestwood 2 participants 2 messages Jan 26, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dhcp-util: fix GCC 10 warning

LEN_CHECK was being fed a hardcoded '1' which was being treated as an int. This led GCC 10.2.1 to emit a warning about comparison between signed/unsigned integers because the builder->max member is unsigned:

ell/dhcp-util.c: In function ‘_dhcp_message_builder_append’:
ell/dhcp-util.c:55:49: error: comparison of integer expressions of different
signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
55 | if ((builder)->pos - (builder)->start + (next) > (builder)->max) \
| ^
ell/dhcp-util.c:65:3: note: in expansion of macro ‘LEN_CHECK’

   65 |   LEN_CHECK(builder, 1);
      |   ^~~~~~~~~

cc1: all warnings being treated as errors

To fix this explicitly use '1U' so the compiler treats it as unsigned.

---
 ell/dhcp-util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ell/dhcp-util.c +1 -1
index 7809e52..af09856 100644
@@ -62,7 +62,7 @@ bool _dhcp_message_builder_append(struct dhcp_message_builder *builder,
 	switch (code) {
 	case DHCP_OPTION_PAD:
 	case DHCP_OPTION_END:
-		LEN_CHECK(builder, 1);
+		LEN_CHECK(builder, 1U);
 
 		builder->pos[0] = code;
 		builder->pos += 1;
Signature · 1 line
2.26.2
#1 lore raw

Hi James,

Quoted 13 lines · James Prestwood

LEN_CHECK was being fed a hardcoded '1' which was being treated as an int. This led GCC 10.2.1 to emit a warning about comparison between signed/unsigned integers because the builder->max member is unsigned:

ell/dhcp-util.c: In function ‘_dhcp_message_builder_append’:
ell/dhcp-util.c:55:49: error: comparison of integer expressions of different

		signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
    55 |  if ((builder)->pos - (builder)->start + (next) > (builder)->max) \
       |                                                 ^
ell/dhcp-util.c:65:3: note: in expansion of macro ‘LEN_CHECK’
    65 |   LEN_CHECK(builder, 1);
       |   ^~~~~~~~~
Quoted 8 lines

cc1: all warnings being treated as errors

To fix this explicitly use '1U' so the compiler treats it as unsigned.

---
  ell/dhcp-util.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis