[glib: 4/6] Fix signedness warning in gio/gbufferedoutputstream.c:g_buffered_output_stream_set_buffer_size()




commit 477d53b2b0b15fc40dc01362ddb6b2c658d8f980
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date:   Mon Nov 16 21:51:34 2020 +0100

    Fix signedness warning in gio/gbufferedoutputstream.c:g_buffered_output_stream_set_buffer_size()
    
    gio/gbufferedoutputstream.c: In function ‘g_buffered_output_stream_set_buffer_size’:
    glib/gmacros.h:806:26: error: comparison of integer expressions of different signedness: ‘gsize’ {aka 
‘long unsigned int’} and ‘goffset’ {aka ‘long int’}
      806 | #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
          |                          ^
    gio/gbufferedoutputstream.c:211:14: note: in expansion of macro ‘MAX’
      211 |       size = MAX (size, priv->pos);
          |              ^~~
    
    Fix signedness warning in gio/gbufferedinputstream.c:g_buffered_input_stream_real_fill()
    
    gio/gbufferedinputstream.c: In function ‘g_buffered_input_stream_real_fill’:
    glib/gmacros.h:809:26: error: comparison of integer expressions of different signedness: ‘gssize’ {aka 
‘long int’} and ‘gsize’ {aka ‘long unsigned int’}K [-Werror=sign-compare]
      809 | #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
          |                          ^
    gio/gbufferedinputstream.c:664:11: note: in expansion of macro ‘MIN’
      664 |   count = MIN (count, priv->len - in_buffer);
          |           ^~~
    gio/gbufferedinputstream.c:667:29: error: comparison of integer expressions of different signedness: 
‘gsize’ {aka ‘long unsigned int’} and ‘gssize’ {aka ‘long int’}
      667 |   if (priv->len - priv->end < count)
          |                             ^
    
    Fix signedness warnings in gio/gbufferedinputstream.c:g_buffered_input_stream_real_fill_async()
    
    gio/gbufferedinputstream.c: In function ‘g_buffered_input_stream_real_fill_async’:
    glib/gmacros.h:809:26: error: comparison of integer expressions of different signedness: ‘gssize’ {aka 
‘long int’} and ‘gsize’ {aka ‘long unsigned int’}
      809 | #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
          |                          ^
    gio/gbufferedinputstream.c:1075:11: note: in expansion of macro ‘MIN’
     1075 |   count = MIN (count, priv->len - in_buffer);
          |           ^~~
    gio/gbufferedinputstream.c:1078:29: error: comparison of integer expressions of different signedness: 
‘gsize’ {aka ‘long unsigned int’} and ‘gssize’ {aka ‘long int’}
     1078 |   if (priv->len - priv->end < count)
          |                             ^

 gio/gbufferedinputstream.c  | 8 ++++----
 gio/gbufferedoutputstream.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gio/gbufferedinputstream.c b/gio/gbufferedinputstream.c
index f5090d064..b0e609c0d 100644
--- a/gio/gbufferedinputstream.c
+++ b/gio/gbufferedinputstream.c
@@ -661,10 +661,10 @@ g_buffered_input_stream_real_fill (GBufferedInputStream  *stream,
   in_buffer = priv->end - priv->pos;
 
   /* Never fill more than can fit in the buffer */
-  count = MIN (count, priv->len - in_buffer);
+  count = MIN ((gsize) count, priv->len - in_buffer);
 
   /* If requested length does not fit at end, compact */
-  if (priv->len - priv->end < count)
+  if (priv->len - priv->end < (gsize) count)
     compact_buffer (stream);
 
   base_stream = G_FILTER_INPUT_STREAM (stream)->base_stream;
@@ -1072,10 +1072,10 @@ g_buffered_input_stream_real_fill_async (GBufferedInputStream *stream,
   in_buffer = priv->end - priv->pos;
 
   /* Never fill more than can fit in the buffer */
-  count = MIN (count, priv->len - in_buffer);
+  count = MIN ((gsize) count, priv->len - in_buffer);
 
   /* If requested length does not fit at end, compact */
-  if (priv->len - priv->end < count)
+  if (priv->len - priv->end < (gsize) count)
     compact_buffer (stream);
 
   task = g_task_new (stream, cancellable, callback, user_data);
diff --git a/gio/gbufferedoutputstream.c b/gio/gbufferedoutputstream.c
index 98bda501d..969bbae0b 100644
--- a/gio/gbufferedoutputstream.c
+++ b/gio/gbufferedoutputstream.c
@@ -208,7 +208,7 @@ g_buffered_output_stream_set_buffer_size (GBufferedOutputStream *stream,
 
   if (priv->buffer)
     {
-      size = MAX (size, priv->pos);
+      size = (priv->pos > 0) ? MAX (size, (gsize) priv->pos) : size;
 
       buffer = g_malloc (size);
       memcpy (buffer, priv->buffer, priv->pos);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]