IMPALA-5031: Zero-length arrays are undefined behavior
This patch prevents the creation of a zero-length array. This is
illegal under paragraph 5 of §6.7.5.2 ("Array declarators") of the C99
standard, which reads:
If the size is an expression that is not an integer constant
expression: if it occurs in a declaration at function prototype
scope, it is treated as if it were replaced by *; otherwise, each
time it is evaluated it shall have a value greater than zero.
Variable-length arrays are not part of C++14, but they are a common
compiler extension and are available in both clang++ and g++. That the
semantics of missing features are the same is implied by [intro.scope]
in the C++14 standard, which reads:
C++ is a general purpose programming language based on the C
programming language as described in ISO/IEC 9899:1999 Programming
languages â C (hereinafter referred to as the C standard).
Change-Id: I93f7d0b0506e4b6a2ff3303477d887a428431f96
Reviewed-on: http://gerrit.cloudera.org:8080/11811
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/8f151d0e
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/8f151d0e
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/8f151d0e
Branch: refs/heads/master
Commit: 8f151d0e63aa5f3548e283fadcaf801456cb3354
Parents: 70fbd1d
Author: Jim Apple <[email protected]>
Authored: Sat Oct 27 16:25:39 2018 -0700
Committer: Impala Public Jenkins <[email protected]>
Committed: Mon Nov 19 23:41:23 2018 +0000
----------------------------------------------------------------------
be/src/runtime/row-batch-serialize-test.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/impala/blob/8f151d0e/be/src/runtime/row-batch-serialize-test.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/row-batch-serialize-test.cc
b/be/src/runtime/row-batch-serialize-test.cc
index e765025..4ea81a6 100644
--- a/be/src/runtime/row-batch-serialize-test.cc
+++ b/be/src/runtime/row-batch-serialize-test.cc
@@ -240,7 +240,7 @@ class RowBatchSerializeTest : public testing::Test {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int len = rand() % (MAX_STRING_LEN + 1);
- char buf[len];
+ char buf[MAX_STRING_LEN];
for (int i = 0; i < len; ++i) {
buf[i] = chars[rand() % (sizeof(chars) - 1)];
}