Replace unportable and overflow-prone use of 'long long' with safer
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Dec 2003 19:56:07 +0000 (19:56 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Dec 2003 19:56:07 +0000 (19:56 +0000)
'double' arithmetic, per recent discussion.

contrib/pg_autovacuum/pg_autovacuum.c
contrib/pgbench/pgbench.c

index 00ccdc68bb8e70ba49b127f45db678c0226fb318..c567c4e7f300c4f461875f95d3ec2df42f18ee12 100644 (file)
@@ -978,7 +978,7 @@ main(int argc, char *argv[])
    db_info    *dbs;
    tbl_info   *tbl;
    PGresult   *res = NULL;
-   long long   diff = 0;
+   double      diff;
    struct timeval now,
                then;
 
@@ -1151,14 +1151,14 @@ main(int argc, char *argv[])
 
        /* Figure out how long to sleep etc ... */
        gettimeofday(&now, 0);
-       diff = (now.tv_sec - then.tv_sec) * 1000000 + (now.tv_usec - then.tv_usec);
+       diff = (int) (now.tv_sec - then.tv_sec) * 1000000.0 + (int) (now.tv_usec - then.tv_usec);
 
-       sleep_secs = args->sleep_base_value + args->sleep_scaling_factor * diff / 1000000;
+       sleep_secs = args->sleep_base_value + args->sleep_scaling_factor * diff / 1000000.0;
        loops++;
        if (args->debug >= 2)
        {
            sprintf(logbuffer,
-            "%i All DBs checked in: %lld usec, will sleep for %i secs.",
+            "%i All DBs checked in: %.0f usec, will sleep for %i secs.",
                    loops, diff, sleep_secs);
            log_entry(logbuffer);
        }
index 3256ebe84b7f080ff204829b2f387d159098e122..398d2114300fe1f091797dd0d4860b30baa405fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.27.2.1 2003/11/26 06:48:53 ishii Exp $
+ * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.27.2.2 2003/12/07 19:56:07 tgl Exp $
  *
  * pgbench: a simple TPC-B like benchmark program for PostgreSQL
  * written by Tatsuo Ishii
@@ -261,14 +261,14 @@ doOne(CState * state, int n, int debug, int ttype)
                 */
                if (use_log)
                {
-                   long long   diff;
+                   double  diff;
                    struct timeval now;
 
                    gettimeofday(&now, 0);
-                   diff = (now.tv_sec - st->txn_begin.tv_sec) * 1000000 +
-                       (now.tv_usec - st->txn_begin.tv_usec);
+                   diff = (int) (now.tv_sec - st->txn_begin.tv_sec) * 1000000.0 +
+                       (int) (now.tv_usec - st->txn_begin.tv_usec);
 
-                   fprintf(LOGFILE, "%d %d %lld\n", st->id, st->cnt, diff);
+                   fprintf(LOGFILE, "%d %d %.0f\n", st->id, st->cnt, diff);
                }
 
                res = PQgetResult(st->con);