Fixed eglib compiler warnings about g_string_truncate() and g_iconv()
authorJeffrey Stedfast <jeff@xamarin.com>
Tue, 13 Aug 2013 15:44:58 +0000 (11:44 -0400)
committerJeffrey Stedfast <jeff@xamarin.com>
Tue, 13 Aug 2013 15:44:58 +0000 (11:44 -0400)
eglib/src/giconv.c
eglib/src/gstring.c

index 9fe0edd3324fc1857cde28612bcc90b01aec8bfa..55e2e8a62b8f8e950c5b7f646a9e4a679b538259 100644 (file)
@@ -180,8 +180,22 @@ g_iconv (GIConv cd, gchar **inbytes, gsize *inbytesleft,
        int rc = 0;
        
 #ifdef HAVE_ICONV
-       if (cd->cd != (iconv_t) -1)
-               return iconv (cd->cd, inbytes, inbytesleft, outbytes, outbytesleft);
+       if (cd->cd != (iconv_t) -1) {
+               /* Note: gsize may have a different size than size_t, so we need to
+                  remap inbytesleft and outbytesleft to size_t's. */
+               size_t *outleftptr;
+               
+               if (outbytesleft) {
+                       outleft = *outbytesleft;
+                       outleftptr = &outleft;
+               } else {
+                       outleftptr = NULL;
+               }
+               
+               inleft = inbytesleft ? *inbytesleft : 0;
+               
+               return iconv (cd->cd, inbytes, &inleft, outbytes, outleftptr);
+       }
 #endif
        
        if (outbytes == NULL || outbytesleft == NULL) {
index 9df5d73c28ef89a6bb83a7976cf88c1d97cfadf4..ba75789bc80788719d2e9ffaf972e835a88f6887 100644 (file)
@@ -235,9 +235,8 @@ g_string_truncate (GString *string, gsize len)
        g_return_val_if_fail (string != NULL, string);
 
        /* Silent return */
-       if (len < 0 || len >= string->len) {
+       if (len >= string->len)
                return string;
-       }
        
        string->len = len;
        string->str[len] = 0;