@@ -188,18 +188,13 @@ dhcp_extract_router_msg(struct buffer *ipbuf)
188188
189189#if defined(_WIN32 ) || defined(DHCP_UNIT_TEST )
190190
191- #if defined(__GNUC__ ) || defined(__clang__ )
192- #pragma GCC diagnostic push
193- #pragma GCC diagnostic ignored "-Wconversion"
194- #endif
195-
196191/*
197192 * Convert DHCP options from the command line / config file
198193 * into a raw DHCP-format options string.
199194 */
200195
201196static void
202- write_dhcp_u8 (struct buffer * buf , const int type , const int data , bool * error )
197+ write_dhcp_u8 (struct buffer * buf , const uint8_t type , const uint8_t data , bool * error )
203198{
204199 if (!buf_safe (buf , 3 ))
205200 {
@@ -213,13 +208,12 @@ write_dhcp_u8(struct buffer *buf, const int type, const int data, bool *error)
213208}
214209
215210static void
216- write_dhcp_u32_array (struct buffer * buf , const int type , const uint32_t * data ,
211+ write_dhcp_u32_array (struct buffer * buf , const uint8_t type , const uint32_t * data ,
217212 const unsigned int len , bool * error )
218213{
219214 if (len > 0 )
220215 {
221- int i ;
222- const int size = len * sizeof (uint32_t );
216+ const size_t size = len * sizeof (uint32_t );
223217
224218 if (!buf_safe (buf , 2 + size ))
225219 {
@@ -230,22 +224,22 @@ write_dhcp_u32_array(struct buffer *buf, const int type, const uint32_t *data,
230224 if (size < 1 || size > 255 )
231225 {
232226 * error = true;
233- msg (M_WARN , "write_dhcp_u32_array: size (%d ) must be > 0 and <= 255" , size );
227+ msg (M_WARN , "write_dhcp_u32_array: size (%zu ) must be > 0 and <= 255" , size );
234228 return ;
235229 }
236230 buf_write_u8 (buf , type );
237- buf_write_u8 (buf , size );
238- for (i = 0 ; i < len ; ++ i )
231+ buf_write_u8 (buf , ( uint8_t ) size );
232+ for (unsigned int i = 0 ; i < len ; ++ i )
239233 {
240234 buf_write_u32 (buf , data [i ]);
241235 }
242236 }
243237}
244238
245239static void
246- write_dhcp_str (struct buffer * buf , const int type , const char * str , bool * error )
240+ write_dhcp_str (struct buffer * buf , const uint8_t type , const char * str , bool * error )
247241{
248- const int len = strlen (str );
242+ const size_t len = strlen (str );
249243 if (!buf_safe (buf , 2 + len ))
250244 {
251245 * error = true;
@@ -259,7 +253,7 @@ write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error)
259253 return ;
260254 }
261255 buf_write_u8 (buf , type );
262- buf_write_u8 (buf , len );
256+ buf_write_u8 (buf , ( uint8_t ) len );
263257 buf_write (buf , str , len );
264258}
265259
@@ -272,15 +266,14 @@ write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error)
272266 * 0x1D 0x7 openvpn 0x3 net 0x00 0x0A duckduckgo 0x3 com 0x00
273267 */
274268static void
275- write_dhcp_search_str (struct buffer * buf , const int type , const char * const * str_array ,
269+ write_dhcp_search_str (struct buffer * buf , const uint8_t type , const char * const * str_array ,
276270 int array_len , bool * error )
277271{
278272 char tmp_buf [256 ];
279- int i ;
280- int len = 0 ;
281- int label_length_pos ;
273+ size_t len = 0 ;
274+ size_t label_length_pos ;
282275
283- for (i = 0 ; i < array_len ; i ++ )
276+ for (int i = 0 ; i < array_len ; i ++ )
284277 {
285278 const char * ptr = str_array [i ];
286279
@@ -301,7 +294,8 @@ write_dhcp_search_str(struct buffer *buf, const int type, const char *const *str
301294 {
302295 if (* ptr == '.' || * ptr == '\0' )
303296 {
304- tmp_buf [label_length_pos ] = (len - label_length_pos ) - 1 ;
297+ /* cast is protected by sizeof(tmp_buf) */
298+ tmp_buf [label_length_pos ] = (char )(len - label_length_pos - 1 );
305299 label_length_pos = len ;
306300 if (* ptr == '\0' )
307301 {
@@ -328,14 +322,10 @@ write_dhcp_search_str(struct buffer *buf, const int type, const char *const *str
328322 }
329323
330324 buf_write_u8 (buf , type );
331- buf_write_u8 (buf , len );
325+ buf_write_u8 (buf , ( uint8_t ) len );
332326 buf_write (buf , tmp_buf , len );
333327}
334328
335- #if defined(__GNUC__ ) || defined(__clang__ )
336- #pragma GCC diagnostic pop
337- #endif
338-
339329bool
340330build_dhcp_options_string (struct buffer * buf , const struct tuntap_options * o )
341331{
0 commit comments