v2-0003-pgbench-Rationalize-types-in-parseScriptWeight.patch
text/x-patch
Filename: v2-0003-pgbench-Rationalize-types-in-parseScriptWeight.patch
Type: text/x-patch
Part: 2
Message:
Re: 64 bit numbers vs format strings
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v2-0003
Subject: pgbench: Rationalize types in parseScriptWeight().
| File | + | − |
|---|---|---|
| src/bin/pgbench/pgbench.c | 4 | 4 |
From 009e52f1b15bd740a6976fd5be673912ce438999 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 6 Dec 2024 09:09:53 +1300
Subject: [PATCH v2 3/5] pgbench: Rationalize types in parseScriptWeight().
This function wants to parse a 64 bit number, but complain if it's out
of range for int, and include the number in the error message. OK, but
long is not always bigger than int, so it won't work the same on all
systems (and the cast to long long in the error message won't really
make it longer).
Parse an int64 with strtoi64(), and print it out with PRId64, so now it
will behave the same everywhere.
---
src/bin/pgbench/pgbench.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index f9d8c7553c5..acf55eccafb 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -6201,7 +6201,7 @@ parseScriptWeight(const char *option, char **script)
if ((sep = strrchr(option, WSEP)))
{
int namelen = sep - option;
- long wtmp;
+ int64 wtmp;
char *badp;
/* generate the script name */
@@ -6211,12 +6211,12 @@ parseScriptWeight(const char *option, char **script)
/* process digits of the weight spec */
errno = 0;
- wtmp = strtol(sep + 1, &badp, 10);
+ wtmp = strtoi64(sep + 1, &badp, 10);
if (errno != 0 || badp == sep + 1 || *badp != '\0')
pg_fatal("invalid weight specification: %s", sep);
if (wtmp > INT_MAX || wtmp < 0)
- pg_fatal("weight specification out of range (0 .. %d): %lld",
- INT_MAX, (long long) wtmp);
+ pg_fatal("weight specification out of range (0 .. %d): %" PRId64,
+ INT_MAX, wtmp);
weight = wtmp;
}
else
--
2.48.1