subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bre...@apache.org
Subject svn commit: r1570038 - /subversion/trunk/subversion/tests/libsvn_repos/repos-test.c
Date Thu, 20 Feb 2014 01:39:00 GMT
Author: breser
Date: Thu Feb 20 01:38:59 2014
New Revision: 1570038

URL: http://svn.apache.org/r1570038
Log:
Fix compiler warning in repos library C tests.

Technically, I could just cast the calculation of max_logs to an (int).  But
this seems more correct to me.  An unlimited log run could return more logs than
a signed int can hold.  We can't possibly return more logs than svn_revnum_t can
hold.  For the purposes of a test it doesn't matter.  However, I view our tests
as also example code and if someone was following this example in a real
implementation I think this code would lead them down a path with potential
problems.  The potential infinite loop issue doesn't apply to real examples
becuase nobody loops the possible limit values except in tests.

* subversion/tests/libsvn_repos/repos-test.c
  (get_logs): Update max_logs, num_logs and num_expected to be svn_revnum_t.
  (log_receiver): Update the type of the baton to match get_logs().


Modified:
    subversion/trunk/subversion/tests/libsvn_repos/repos-test.c

Modified: subversion/trunk/subversion/tests/libsvn_repos/repos-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_repos/repos-test.c?rev=1570038&r1=1570037&r2=1570038&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_repos/repos-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_repos/repos-test.c Thu Feb 20 01:38:59 2014
@@ -2889,7 +2889,7 @@ log_receiver(void *baton,
              svn_log_entry_t *log_entry,
              apr_pool_t *pool)
 {
-  int *count = baton;
+  svn_revnum_t *count = baton;
   (*count)++;
   return SVN_NO_ERROR;
 }
@@ -2947,13 +2947,18 @@ get_logs(const svn_test_opts_t *opts,
           svn_revnum_t end_arg   = end ? end : SVN_INVALID_REVNUM;
           svn_revnum_t eff_start = start ? start : youngest_rev;
           svn_revnum_t eff_end   = end ? end : youngest_rev;
-          int limit, max_logs =
+          int limit;
+          svn_revnum_t max_logs =
             MAX(eff_start, eff_end) + 1 - MIN(eff_start, eff_end);
-          int num_logs;
+          svn_revnum_t num_logs;
 
+          /* this may look like it can get in an infinite loop if max_logs
+           * ended up being larger than the size limit can represent.  It
+           * can't because a negative limit will end up failing to match
+           * the existed number of logs. */
           for (limit = 0; limit <= max_logs; limit++)
             {
-              int num_expected = limit ? limit : max_logs;
+              svn_revnum_t num_expected = limit ? limit : max_logs;
 
               svn_pool_clear(subpool);
               num_logs = 0;
@@ -2964,7 +2969,7 @@ get_logs(const svn_test_opts_t *opts,
               if (num_logs != num_expected)
                 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
                                          "Log with start=%ld,end=%ld,limit=%d "
-                                         "returned %d entries (expected %d)",
+                                         "returned %ld entries (expected %ld)",
                                          start_arg, end_arg, limit,
                                          num_logs, max_logs);
             }



Mime
View raw message