Skip to content

Commit 8060672

Browse files
author
Artem Fadeev
committed
Fix svace warnings
Fixed arithmetics in check_dsa_file_size to avoid server startup failure when aqo.dsm_size_max in bytes overflows signed integer. Updated corresponding tap-test. Two unreachable paths were removed. (cherry-picked from master with a minor change in tap-test)
1 parent bc900f7 commit 8060672

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Diff for: cardinality_hooks.c

-3
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,6 @@ aqo_estimate_num_groups(PlannerInfo *root, List *groupExprs,
447447
/* It is unclear that to do in situation of such kind. Just report it */
448448
elog(WARNING, "AQO is in the middle of the estimate_num_groups_hook chain");
449449

450-
if (groupExprs == NIL)
451-
return 1.0;
452-
453450
old_ctx_m = MemoryContextSwitchTo(AQOPredictMemCtx);
454451

455452
predicted = predict_num_groups(root, subpath, groupExprs, &fss);

Diff for: storage.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,6 @@ aqo_get_file_size(const char *filename)
968968
ereport(LOG,
969969
(errcode_for_file_access(),
970970
errmsg("could not read file \"%s\": %m", filename)));
971-
if (file)
972-
FreeFile(file);
973971
unlink(filename);
974972
return -1;
975973
}
@@ -981,7 +979,7 @@ check_dsa_file_size(void)
981979
long data_size = aqo_get_file_size(PGAQO_DATA_FILE);
982980

983981
if (qtext_size == -1 || data_size == -1 ||
984-
qtext_size + data_size >= dsm_size_max * 1024 * 1024)
982+
((unsigned long) qtext_size + (unsigned long) data_size) >> 20 >= dsm_size_max)
985983
{
986984
elog(ERROR, "aqo.dsm_size_max is too small");
987985
}

Diff for: t/004_dsm_size_max.pl

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PostgreSQL::Test::Cluster;
66
use PostgreSQL::Test::Utils;
77

8-
use Test::More tests => 5;
8+
use Test::More tests => 6;
99

1010
my $node = PostgreSQL::Test::Cluster->new('aqotest');
1111
$node->init;
@@ -58,6 +58,12 @@
5858
$node->psql('postgres', 'select * from aqo_reset();');
5959
$node->stop();
6060

61+
# 3000mb (more than 2*31 bytes) overflows 4-byte signed int
62+
$node->append_conf('postgresql.conf', 'aqo.dsm_size_max = 3000');
63+
is($node->start(fail_ok => 1), 1, "Large aqo.dsm_size_max doesn't cause integer overflow");
64+
$node->stop();
65+
66+
6167
my $regex;
6268
$long_string = 'a' x 100000;
6369
$regex = qr/.*WARNING: \[AQO\] Not enough DSA\. AQO was disabled for this query/;

0 commit comments

Comments
 (0)