]> granicus.if.org Git - transmission/commitdiff
Ongoing refactoring (use size_t instead of int)
authorMike Gelfand <mikedld@mikedld.com>
Fri, 25 Dec 2015 10:19:50 +0000 (10:19 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Fri, 25 Dec 2015 10:19:50 +0000 (10:19 +0000)
19 files changed:
daemon/remote.c
gtk/tr-prefs.c
libtransmission/ConvertUTF.c
libtransmission/ConvertUTF.h
libtransmission/announcer-udp.c
libtransmission/announcer.c
libtransmission/platform.c
libtransmission/rpc-server.c
libtransmission/rpc-test.c
libtransmission/rpcimpl.c
libtransmission/rpcimpl.h
libtransmission/transmission.h
libtransmission/utils-test.c
libtransmission/utils.c
libtransmission/utils.h
libtransmission/variant.c
libtransmission/variant.h
qt/TrackerDelegate.cc
utils/edit.c

index 5187ceafede47a590a92b725127b18a4da160f0c..ea9e1cbf0024f0e2e62de1eb2b33d6f5daa556b6 100644 (file)
@@ -577,7 +577,7 @@ addDays (tr_variant * args, const tr_quark key, const char * arg)
       int valueCount;
       int * values;
 
-      values = tr_parseNumberRange (arg, -1, &valueCount);
+      values = tr_parseNumberRange (arg, TR_BAD_SIZE, &valueCount);
       for (i=0; i<valueCount; ++i)
         {
           if (values[i] < 0 || values[i] > 7)
@@ -615,7 +615,7 @@ addFiles (tr_variant      * args,
     {
       int i;
       int valueCount;
-      int * values = tr_parseNumberRange (arg, -1, &valueCount);
+      int * values = tr_parseNumberRange (arg, TR_BAD_SIZE, &valueCount);
 
       for (i=0; i<valueCount; ++i)
         tr_variantListAddInt (files, values[i]);
index 0e14a87ab9eb4b820bce2cc387ee2b353da887f3..4906e5ab0ceed6e0ea526ec41946b027eb75d928 100644 (file)
@@ -501,7 +501,7 @@ static void
 on_blocklist_url_changed (GtkEditable * e, gpointer gbutton)
 {
   gchar * url = gtk_editable_get_chars (e, 0, -1);
-  const gboolean err = tr_urlParse (url, -1, NULL, NULL, NULL, NULL);
+  const gboolean err = tr_urlParse (url, TR_BAD_SIZE, NULL, NULL, NULL, NULL);
   gtk_widget_set_sensitive (GTK_WIDGET (gbutton), !err);
   g_free (url);
 }
index 84215ff3224a65a714772509d7b51a819d542a07..dcc79e2e49b505f6f40054dd5851fe8b5f8ae035 100644 (file)
@@ -43,6 +43,9 @@
  #include <stdio.h>
 #endif
 #include <string.h> /* strlen () */
+
+#include "transmission.h"
+
 #include "ConvertUTF.h"
 
 static const int halfShift  = 10; /* used for shifting by 10 bits */
@@ -350,7 +353,7 @@ Boolean isLegalUTF8Sequence (const UTF8 *source, const UTF8 *sourceEnd) {
  * In addition to knowing if the sequence is legal, it also tells you the last good character.
  */
 Boolean
-tr_utf8_validate (const char * str, int max_len, const char ** end)
+tr_utf8_validate (const char * str, size_t max_len, const char ** end)
 {
     const UTF8* source = (const UTF8*) str;
     const UTF8* sourceEnd;
@@ -361,7 +364,7 @@ tr_utf8_validate (const char * str, int max_len, const char ** end)
     if (str == NULL)
         return false;
 
-    sourceEnd = source + ((max_len < 0) ? strlen (str) : (size_t)max_len);
+    sourceEnd = source + (max_len == TR_BAD_SIZE ? strlen (str) : max_len);
 
     if (source == sourceEnd)
     {
@@ -390,8 +393,6 @@ tr_utf8_validate (const char * str, int max_len, const char ** end)
             return true;
         }
     }
-
-    
 }
 
 
index 8a57fa979c957a37ec12a9d6a3b08eb02d245228..cd21fa9312609f9ac3dad5ee558cf9ac4e567e1d 100644 (file)
@@ -151,7 +151,7 @@ Boolean isLegalUTF8Sequence (const UTF8 *source, const UTF8 *sourceEnd);
 
 
 /* intended to work the same as g_utf8_validate */
-Boolean tr_utf8_validate (const char * str, int max_len, const char ** end);
+Boolean tr_utf8_validate (const char * str, size_t max_len, const char ** end);
 
 
 #ifdef __cplusplus
index 00107cdf9f9f1f6d44550c61e01fe2a6b1221ba8..c3aec353b4069857101bcf493fefed4b05b709df 100644 (file)
@@ -763,7 +763,7 @@ tau_session_get_tracker (struct tr_announcer_udp * tau, const char * url)
     struct tau_tracker * tracker = NULL;
 
     /* see if we've already got a tracker that matches this host + port */
-    tr_urlParse (url, -1, NULL, &host, &port, NULL);
+    tr_urlParse (url, TR_BAD_SIZE, NULL, &host, &port, NULL);
     key = tr_strdup_printf ("%s:%d", host, port);
     for (i=0, n=tr_ptrArraySize (&tau->trackers); !tracker && i<n; ++i) {
         struct tau_tracker * tmp = tr_ptrArrayNth (&tau->trackers, i);
index 4af98096b2e84e16e65a6647d35f59569bf07cb7..44eeb9fb2305db641e6632e41c51e696d009bb40 100644 (file)
@@ -229,7 +229,7 @@ getKey (const char * url)
     char * host = NULL;
     int port = 0;
 
-    tr_urlParse (url, -1, &scheme, &host, &port, NULL);
+    tr_urlParse (url, TR_BAD_SIZE, &scheme, &host, &port, NULL);
     ret = tr_strdup_printf ("%s://%s:%d", (scheme?scheme:"invalid"), (host?host:"invalid"), port);
 
     tr_free (host);
@@ -583,7 +583,7 @@ filter_trackers (tr_tracker_info * input, int input_count, int * setme_count)
             char * host;
             char * path;
             bool is_duplicate = false;
-            tr_urlParse (input[i].announce, -1, &scheme, &host, &port, &path);
+            tr_urlParse (input[i].announce, TR_BAD_SIZE, &scheme, &host, &port, &path);
 
             /* weed out one common source of duplicates:
              * "http://tracker/announce" +
index ec700f271af106b35e78d6f317058471df9d2d34..7b7c3c273d78f6463b23d10159e99c5656fac2c8 100644 (file)
@@ -553,7 +553,7 @@ tr_getWebClientDir (const tr_session * session UNUSED)
                 if (end)
                   {
                     if ((end - tmp) > 1)
-                      tr_list_append (&candidates, tr_strndup (tmp, end - tmp));
+                      tr_list_append (&candidates, tr_strndup (tmp, (size_t) (end - tmp)));
                     tmp = (char *) end + 1;
                   }
                 else if (tmp && *tmp)
index df7e69e50c5ce23a9b9b21e193198d7a1f088060..cd3e0290c172ae0183120e4c5fad1916e86283bf 100644 (file)
@@ -130,9 +130,9 @@ send_simple_response (struct evhttp_request * req,
 struct tr_mimepart
 {
   char * headers;
-  int headers_len;
+  size_t headers_len;
   char * body;
-  int body_len;
+  size_t body_len;
 };
 
 static void
@@ -176,9 +176,9 @@ extract_parts_from_multipart (const struct evkeyvalq  * headers,
           if (rnrn)
             {
               struct tr_mimepart * p = tr_new (struct tr_mimepart, 1);
-              p->headers_len = rnrn - part;
+              p->headers_len = (size_t) (rnrn - part);
               p->headers = tr_strndup (part, p->headers_len);
-              p->body_len = (part+part_len) - (rnrn + 4);
+              p->body_len = (size_t) ((part + part_len) - (rnrn + 4));
               p->body = tr_strndup (rnrn+4, p->body_len);
               tr_ptrArrayAppend (setme_parts, p);
             }
@@ -221,7 +221,7 @@ handle_upload (struct evhttp_request * req,
         {
           const struct tr_mimepart * p = tr_ptrArrayNth (&parts, i);
           const char * ours = get_current_session_id (server);
-          const int ourlen = strlen (ours);
+          const size_t ourlen = strlen (ours);
           hasSessionId = ourlen<=p->body_len && !memcmp (p->body, ours, ourlen);
         }
 
@@ -237,7 +237,7 @@ handle_upload (struct evhttp_request * req,
       else for (i=0; i<n; ++i)
         {
           struct tr_mimepart * p = tr_ptrArrayNth (&parts, i);
-          int body_len = p->body_len;
+          size_t body_len = p->body_len;
           tr_variant top, *args;
           tr_variant test;
           bool have_source = false;
@@ -563,7 +563,7 @@ handle_rpc (struct evhttp_request * req, struct tr_rpc_server  * server)
       struct rpc_response_data * data = tr_new0 (struct rpc_response_data, 1);
       data->req = req;
       data->server = server;
-      tr_rpc_request_exec_uri (server->session, q+1, -1, rpc_response_func, data);
+      tr_rpc_request_exec_uri (server->session, q + 1, TR_BAD_SIZE, rpc_response_func, data);
     }
   else
     {
index 7330f4b88471a08fca184e7e363964a4f5cdb96c..2f3f0b73c6f4190d0f345f6f284bf32f695a6fa9 100644 (file)
@@ -22,7 +22,7 @@ test_list (void)
   const char * str;
   tr_variant top;
 
-  tr_rpc_parse_list_str (&top, "12", -1);
+  tr_rpc_parse_list_str (&top, "12", TR_BAD_SIZE);
   check (tr_variantIsInt (&top));
   check (tr_variantGetInt (&top, &i));
   check_int_eq (12, i);
@@ -34,7 +34,7 @@ test_list (void)
   check_int_eq (1, i);
   tr_variantFree (&top);
 
-  tr_rpc_parse_list_str (&top, "6,7", -1);
+  tr_rpc_parse_list_str (&top, "6,7", TR_BAD_SIZE);
   check (tr_variantIsList (&top));
   check (tr_variantListSize (&top) == 2);
   check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
@@ -43,14 +43,14 @@ test_list (void)
   check_int_eq (7, i);
   tr_variantFree (&top);
 
-  tr_rpc_parse_list_str (&top, "asdf", -1);
+  tr_rpc_parse_list_str (&top, "asdf", TR_BAD_SIZE);
   check (tr_variantIsString (&top));
   check (tr_variantGetStr (&top, &str, &len));
   check_int_eq (4, len);
   check_streq ("asdf", str);
   tr_variantFree (&top);
 
-  tr_rpc_parse_list_str (&top, "1,3-5", -1);
+  tr_rpc_parse_list_str (&top, "1,3-5", TR_BAD_SIZE);
   check (tr_variantIsList (&top));
   check (tr_variantListSize (&top) == 4);
   check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
index cb09f925d1216bfd1ea19649bed809877041ece6..04281842475520f5fcda0ae9550d224088b0af5b 100644 (file)
@@ -2299,7 +2299,7 @@ tr_rpc_request_exec_json (tr_session            * session,
 void
 tr_rpc_parse_list_str (tr_variant  * setme,
                        const char  * str,
-                       int           len)
+                       size_t        len)
 
 {
   int valueCount;
@@ -2329,14 +2329,14 @@ tr_rpc_parse_list_str (tr_variant  * setme,
 void
 tr_rpc_request_exec_uri (tr_session           * session,
                          const void           * request_uri,
-                         int                    request_len,
+                         size_t                 request_uri_len,
                          tr_rpc_response_func   callback,
                          void                 * callback_user_data)
 {
   const char * pch;
   tr_variant top;
   tr_variant * args;
-  char * request = tr_strndup (request_uri, request_len);
+  char * request = tr_strndup (request_uri, request_uri_len);
 
   tr_variantInitDict (&top, 3);
   args = tr_variantDictAddDict (&top, TR_KEY_arguments, 0);
@@ -2349,11 +2349,11 @@ tr_rpc_request_exec_uri (tr_session           * session,
       const char * next = strchr (pch, '&');
       if (delim)
         {
-          char * key = tr_strndup (pch, delim - pch);
+          char * key = tr_strndup (pch, (size_t) (delim - pch));
           int isArg = strcmp (key, "method") && strcmp (key, "tag");
           tr_variant * parent = isArg ? args : &top;
 
-          tr_rpc_parse_list_str (tr_variantDictAdd (parent, tr_quark_new (key, delim-pch)),
+          tr_rpc_parse_list_str (tr_variantDictAdd (parent, tr_quark_new (key, (size_t) (delim - pch))),
                                  delim + 1,
                                  next ? (size_t)(next - (delim + 1)) : strlen (delim + 1));
           tr_free (key);
index 147ae75baaa15b39c5d0b3337c648fcc3750803a..cdc65fa766fa6fc87d25882c6ff93d719cd6f984 100644 (file)
@@ -34,13 +34,13 @@ void tr_rpc_request_exec_json (tr_session            * session,
 /* see the RPC spec's "Request URI Notation" section */
 void tr_rpc_request_exec_uri (tr_session           * session,
                               const void           * request_uri,
-                              int                    request_len,
+                              size_t                 request_uri_len,
                               tr_rpc_response_func   callback,
                               void                 * callback_user_data);
 
 void tr_rpc_parse_list_str (tr_variant  * setme,
                             const char  * list_str,
-                            int           list_str_len);
+                            size_t        list_str_len);
 
 #ifdef __cplusplus
 }
index 8605483892d16904445683e752a68ac3acf56991..06a0834c17ae224612a83b673dd38d4b80410a53 100644 (file)
@@ -89,6 +89,8 @@ extern "C" {
 
 #define SHA_DIGEST_LENGTH 20
 #define TR_INET6_ADDRSTRLEN 46
+#define TR_BAD_SIZE ((size_t) -1)
 
 typedef uint32_t tr_file_index_t;
 typedef uint32_t tr_piece_index_t;
index f7c6f54284900148a69a451871fffba371c3b6ee..deb67916095c7061b27055bd51a44b7687047bf1 100644 (file)
@@ -105,7 +105,7 @@ test_utf8 (void)
   char * out;
 
   in = "hello world";
-  out = tr_utf8clean (in, -1);
+  out = tr_utf8clean (in, TR_BAD_SIZE);
   check_streq (in, out);
   tr_free (out);
 
@@ -119,14 +119,14 @@ test_utf8 (void)
   out = tr_utf8clean (in, 17);
   check (out != NULL);
   check ((strlen (out) == 17) || (strlen (out) == 33));
-  check (tr_utf8_validate (out, -1, NULL));
+  check (tr_utf8_validate (out, TR_BAD_SIZE, NULL));
   tr_free (out);
 
   /* same string, but utf-8 clean */
   in = "Трудно быть Богом";
-  out = tr_utf8clean (in, -1);
+  out = tr_utf8clean (in, TR_BAD_SIZE);
   check (out != NULL);
-  check (tr_utf8_validate (out, -1, NULL));
+  check (tr_utf8_validate (out, TR_BAD_SIZE, NULL));
   check_streq (in, out);
   tr_free (out);
 
@@ -140,7 +140,7 @@ test_numbers (void)
   int count;
   int * numbers;
 
-  numbers = tr_parseNumberRange ("1-10,13,16-19", -1, &count);
+  numbers = tr_parseNumberRange ("1-10,13,16-19", TR_BAD_SIZE, &count);
   check_int_eq (15, count);
   check_int_eq (1, numbers[0]);
   check_int_eq (6, numbers[5]);
@@ -150,22 +150,22 @@ test_numbers (void)
   check_int_eq (19, numbers[14]);
   tr_free (numbers);
 
-  numbers = tr_parseNumberRange ("1-5,3-7,2-6", -1, &count);
+  numbers = tr_parseNumberRange ("1-5,3-7,2-6", TR_BAD_SIZE, &count);
   check (count == 7);
   check (numbers != NULL);
   for (i=0; i<count; ++i)
     check_int_eq (i+1, numbers[i]);
   tr_free (numbers);
 
-  numbers = tr_parseNumberRange ("1-Hello", -1, &count);
+  numbers = tr_parseNumberRange ("1-Hello", TR_BAD_SIZE, &count);
   check_int_eq (0, count);
   check (numbers == NULL);
 
-  numbers = tr_parseNumberRange ("1-", -1, &count);
+  numbers = tr_parseNumberRange ("1-", TR_BAD_SIZE, &count);
   check_int_eq (0, count);
   check (numbers == NULL);
 
-  numbers = tr_parseNumberRange ("Hello", -1, &count);
+  numbers = tr_parseNumberRange ("Hello", TR_BAD_SIZE, &count);
   check_int_eq (0, count);
   check (numbers == NULL);
 
@@ -317,7 +317,7 @@ test_url (void)
   const char * url;
 
   url = "http://1";
-  check (!tr_urlParse (url, -1, &scheme, &host, &port, &path));
+  check (!tr_urlParse (url, TR_BAD_SIZE, &scheme, &host, &port, &path));
   check_streq ("http", scheme);
   check_streq ("1", host);
   check_streq ("/", path);
@@ -327,7 +327,7 @@ test_url (void)
   tr_free (host);
 
   url = "http://www.some-tracker.org/some/path";
-  check (!tr_urlParse (url, -1, &scheme, &host, &port, &path));
+  check (!tr_urlParse (url, TR_BAD_SIZE, &scheme, &host, &port, &path));
   check_streq ("http", scheme);
   check_streq ("www.some-tracker.org", host);
   check_streq ("/some/path", path);
@@ -337,7 +337,7 @@ test_url (void)
   tr_free (host);
 
   url = "http://www.some-tracker.org:80/some/path";
-  check (!tr_urlParse (url, -1, &scheme, &host, &port, &path));
+  check (!tr_urlParse (url, TR_BAD_SIZE, &scheme, &host, &port, &path));
   check_streq ("http", scheme);
   check_streq ("www.some-tracker.org", host);
   check_streq ("/some/path", path);
index 099a551a56f843ba5e895aca4918acb9bdef2c61..ef120b406cf2ba1c1f767e34edcb37f35cf6a2e7 100644 (file)
@@ -365,15 +365,15 @@ evbuffer_free_to_str (struct evbuffer * buf,
 char*
 tr_strdup (const void * in)
 {
-  return tr_strndup (in, in ? (int)strlen ((const char *)in) : 0);
+  return tr_strndup (in, in != NULL ? strlen (in) : 0);
 }
 
 char*
-tr_strndup (const void * in, int len)
+tr_strndup (const void * in, size_t len)
 {
   char * out = NULL;
 
-  if (len < 0)
+  if (len == TR_BAD_SIZE)
     {
       out = tr_strdup (in);
     }
@@ -671,7 +671,7 @@ tr_hex_to_binary (const char * input,
 ***/
 
 static bool
-isValidURLChars (const char * url, int url_len)
+isValidURLChars (const char * url, size_t url_len)
 {
   const char * c;
   const char * end;
@@ -706,7 +706,7 @@ tr_urlIsValidTracker (const char * url)
     }
   else
     {
-      const int len = strlen (url);
+      const size_t len = strlen (url);
 
       valid = isValidURLChars (url, len)
            && !tr_urlParse (url, len, NULL, NULL, NULL, NULL)
@@ -718,7 +718,7 @@ tr_urlIsValidTracker (const char * url)
 
 /** @brief return true if the URL is a http or https or ftp or sftp one that Transmission understands */
 bool
-tr_urlIsValid (const char * url, int url_len)
+tr_urlIsValid (const char * url, size_t url_len)
 {
   bool valid;
 
@@ -728,7 +728,7 @@ tr_urlIsValid (const char * url, int url_len)
     }
   else
     {
-      if (url_len < 0)
+      if (url_len == TR_BAD_SIZE)
         url_len = strlen (url);
 
       valid = isValidURLChars (url, url_len)
@@ -748,7 +748,7 @@ tr_addressIsIP (const char * str)
 
 int
 tr_urlParse (const char * url_in,
-             int          len,
+             size_t       len,
              char **      setme_protocol,
              char **      setme_host,
              int *        setme_port,
@@ -756,7 +756,7 @@ tr_urlParse (const char * url_in,
 {
   int err;
   int port = 0;
-  int n;
+  size_t n;
   char * tmp;
   char * pch;
   size_t host_len;
@@ -770,7 +770,7 @@ tr_urlParse (const char * url_in,
     {
       *pch = '\0';
       protocol = tmp;
-      protocol_len = pch - protocol;
+      protocol_len = (size_t) (pch - protocol);
       pch += 3;
       if ((n = strcspn (pch, ":/")))
         {
@@ -1041,20 +1041,20 @@ to_utf8 (const char * in, size_t inlen)
 }
 
 char*
-tr_utf8clean (const char * str, int max_len)
+tr_utf8clean (const char * str, size_t max_len)
 {
   char * ret;
   const char * end;
 
-  if (max_len < 0)
-    max_len = (int) strlen (str);
+  if (max_len == TR_BAD_SIZE)
+    max_len = strlen (str);
 
   if (tr_utf8_validate (str, max_len, &end))
     ret = tr_strndup (str, max_len);
   else
     ret = to_utf8 (str, max_len);
 
-  assert (tr_utf8_validate (ret, -1, NULL));
+  assert (tr_utf8_validate (ret, TR_BAD_SIZE, NULL));
   return ret;
 }
 
@@ -1234,7 +1234,7 @@ struct number_range
  * Anything else is an error and will return failure.
  */
 static bool
-parseNumberSection (const char * str, int len, struct number_range * setme)
+parseNumberSection (const char * str, size_t len, struct number_range * setme)
 {
   long a, b;
   bool success;
@@ -1289,7 +1289,7 @@ compareInt (const void * va, const void * vb)
  * If a fragment of the string can't be parsed, NULL is returned.
  */
 int*
-tr_parseNumberRange (const char * str_in, int len, int * setmeCount)
+tr_parseNumberRange (const char * str_in, size_t len, int * setmeCount)
 {
   int n = 0;
   int * uniq = NULL;
@@ -1305,7 +1305,7 @@ tr_parseNumberRange (const char * str_in, int len, int * setmeCount)
       const char * pch = strchr (walk, ',');
       if (pch)
         {
-          success = parseNumberSection (walk, pch-walk, &range);
+          success = parseNumberSection (walk, (size_t) (pch - walk), &range);
           walk = pch + 1;
         }
       else
index 8213b5b859b5e2e5daf844f77a2cc8a971d3c87a..43268bc3e17ac35193ddb048a578a3f2b2eb18e3 100644 (file)
@@ -190,7 +190,7 @@ void tr_wait_msec (long int delay_milliseconds);
  * @param str the string to make a clean copy of
  * @param len the length of the string to copy. If -1, the entire string is used.
  */
-char* tr_utf8clean (const char * str, int len) TR_GNUC_MALLOC;
+char* tr_utf8clean (const char * str, size_t len) TR_GNUC_MALLOC;
 
 #ifdef _WIN32
 
@@ -283,7 +283,7 @@ void* tr_valloc (size_t bufLen);
  * @param len length of the substring to copy. if a length less than zero is passed in, strlen (len) is used
  * @return a newly-allocated copy of `in' that can be freed with tr_free ()
  */
-char* tr_strndup (const void * in, int len) TR_GNUC_MALLOC;
+char* tr_strndup (const void * in, size_t len) TR_GNUC_MALLOC;
 
 /**
  * @brief make a newly-allocated copy of a string
@@ -363,12 +363,12 @@ bool tr_addressIsIP (const char * address);
 bool tr_urlIsValidTracker (const char * url) TR_GNUC_NONNULL (1);
 
 /** @brief return true if the url is a [ http, https, ftp, ftps ] url that Transmission understands */
-bool tr_urlIsValid (const char * url, int url_len) TR_GNUC_NONNULL (1);
+bool tr_urlIsValid (const char * url, size_t url_len) TR_GNUC_NONNULL (1);
 
 /** @brief parse a URL into its component parts
     @return zero on success or an error number if an error occurred */
 int  tr_urlParse (const char * url,
-                  int          url_len,
+                  size_t       url_len,
                   char      ** setme_scheme,
                   char      ** setme_host,
                   int        * setme_port,
@@ -388,8 +388,8 @@ double tr_getRatio (uint64_t numerator, uint64_t denominator);
  * For example, "5-8" will return [ 5, 6, 7, 8 ] and setmeCount will be 4.
  */
 int* tr_parseNumberRange (const char * str,
-                          int str_len,
-                          int * setmeCount) TR_GNUC_MALLOC TR_GNUC_NONNULL (1);
+                          size_t       str_len,
+                          int        * setmeCount) TR_GNUC_MALLOC TR_GNUC_NONNULL (1);
 
 
 /**
index d5b85f0d99af6a2cf7f37aa38c69b578711acbf4..3ca050c528e7d6b875f22d3311dae3bf02477b69 100644 (file)
@@ -187,16 +187,16 @@ tr_variant_string_set_quark (struct tr_variant_string  * str,
 static void
 tr_variant_string_set_string (struct tr_variant_string  * str,
                               const char                * bytes,
-                              int                         len)
+                              size_t                      len)
 {
   tr_variant_string_clear (str);
 
   if (bytes == NULL)
     len = 0;
-  else if (len < 0)
+  else if (len == TR_BAD_SIZE)
     len = strlen (bytes);
 
-  if ((size_t)len < sizeof(str->str.buf))
+  if (len < sizeof (str->str.buf))
     {
       str->type = TR_STRING_TYPE_BUF;
       memcpy (str->str.buf, bytes, len);
@@ -476,7 +476,7 @@ tr_variantInitQuark (tr_variant * v, const tr_quark q)
 }
 
 void
-tr_variantInitStr (tr_variant * v, const void * str, int len)
+tr_variantInitStr (tr_variant * v, const void * str, size_t len)
 {
   tr_variantInit (v, TR_VARIANT_TYPE_STR);
   tr_variant_string_set_string (&v->val.s, str, len);
@@ -598,7 +598,7 @@ tr_variantListAddStr (tr_variant  * list,
                       const char  * val)
 {
   tr_variant * child = tr_variantListAdd (list);
-  tr_variantInitStr (child, val, -1);
+  tr_variantInitStr (child, val, TR_BAD_SIZE);
   return child;
 }
 
@@ -727,7 +727,7 @@ tr_variantDictAddStr (tr_variant      * dict,
                       const char      * val)
 {
   tr_variant * child = dictFindOrAdd (dict, key, TR_VARIANT_TYPE_STR);
-  tr_variantInitStr (child, val, -1);
+  tr_variantInitStr (child, val, TR_BAD_SIZE);
   return child;
 }
 
index 60ec5ed72ca22bede4c4094f4f542ccb5f0f334a..e46b781497f2d499ef2cd2ee934e5ea8cf40487d 100644 (file)
@@ -206,7 +206,7 @@ bool         tr_variantGetStr          (const tr_variant * variant,
 
 void         tr_variantInitStr         (tr_variant       * initme,
                                         const void       * str,
-                                        int                str_len);
+                                        size_t             str_len);
 
 void         tr_variantInitQuark       (tr_variant       * initme,
                                         const tr_quark     quark);
index 23018734e1541ea42ebe0e0e8970734c3ac33d37..f538d8837bce79581b8e617bf84b74d60b08ed09 100644 (file)
@@ -193,7 +193,7 @@ TrackerDelegate::getText (const TrackerInfo& inf) const
   str += inf.st.isBackup ? QLatin1String ("<i>") : QLatin1String ("<b>");
   char * host = NULL;
   int port = 0;
-  tr_urlParse (inf.st.announce.toUtf8().constData(), -1, NULL, &host, &port, NULL);
+  tr_urlParse (inf.st.announce.toUtf8().constData(), TR_BAD_SIZE, NULL, &host, &port, NULL);
   str += QString::fromLatin1 ("%1:%2").arg (QString::fromUtf8 (host)).arg (port);
   tr_free (host);
   if (!key.isEmpty()) str += QLatin1String (" - ") + key;
index 6c2b186ef9d122315670df95f00b0edc972470b9..0ce6eaa5c821d063eec7524f26521a3d3cc40075 100644 (file)
@@ -211,7 +211,7 @@ replaceURL (tr_variant * metainfo, const char * in, const char * out)
                   char * newstr = replaceSubstr (str, in, out);
                   printf ("\tReplaced in \"announce-list\" tier %d: \"%s\" --> \"%s\"\n", tierCount, str, newstr);
                   tr_variantFree (node);
-                  tr_variantInitStr (node, newstr, -1);
+                  tr_variantInitStr (node, newstr, TR_BAD_SIZE);
                   tr_free (newstr);
                   changed = true;
                 }