Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc33d1a8

Browse files
committed
pgbench: Install guard against overflow when dividing by -1.
Commit64f5edc fixed the same hazardon master; this is a backport, but the modulo operator does not existin older releases.Michael Paquier
1 parentaa223a0 commitc33d1a8

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
#ifndefINT64_MAX
5353
#defineINT64_MAXINT64CONST(0x7FFFFFFFFFFFFFFF)
5454
#endif
55+
#ifndefINT64_MIN
56+
#defineINT64_MIN(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
57+
#endif
58+
5559

5660
/*
5761
* Multi-platform pthread implementations
@@ -1510,13 +1514,37 @@ doCustom(TState *thread, CState *st, instr_time *conn_time, FILE *logfile, AggVa
15101514
snprintf(res,sizeof(res),INT64_FORMAT,ope1*ope2);
15111515
elseif (strcmp(argv[3],"/")==0)
15121516
{
1517+
int64operes;
1518+
15131519
if (ope2==0)
15141520
{
15151521
fprintf(stderr,"%s: division by zero\n",argv[0]);
15161522
st->ecnt++;
15171523
return true;
15181524
}
1519-
snprintf(res,sizeof(res),INT64_FORMAT,ope1 /ope2);
1525+
/*
1526+
* INT64_MIN / -1 is problematic, since the result can't
1527+
* be represented on a two's-complement machine. Some
1528+
* machines produce INT64_MIN, some produce zero, some
1529+
* throw an exception. We can dodge the problem by
1530+
* recognizing that division by -1 is the same as
1531+
* negation.
1532+
*/
1533+
if (ope2==-1)
1534+
{
1535+
operes=-ope1;
1536+
1537+
/* overflow check (needed for INT64_MIN) */
1538+
if (ope1==INT64_MIN)
1539+
{
1540+
fprintf(stderr,"bigint out of range\n");
1541+
st->ecnt++;
1542+
return true;
1543+
}
1544+
}
1545+
else
1546+
operes=ope1 /ope2;
1547+
snprintf(res,sizeof(res),INT64_FORMAT,operes);
15201548
}
15211549
else
15221550
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp