Skip to content

Commit

Permalink
[BUG] Fixed some uninitialized variables (apache#5850)
Browse files Browse the repository at this point in the history
Fixed some potential bugs caused by uninitialized variables
  • Loading branch information
stdpain authored and morningman-cmy committed May 26, 2021
1 parent e158aea commit f70b55f
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 298 deletions.
8 changes: 6 additions & 2 deletions be/src/exec/csv_scan_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ CsvScanNode::CsvScanNode(ObjectPool* pool, const TPlanNode& tnode, const Descrip
_default_values(tnode.csv_scan_node.default_values),
_is_init(false),
_tuple_desc(nullptr),
_slot_num(0),
_tuple_pool(nullptr),
_text_converter(nullptr),
_tuple(nullptr),
_runtime_state(nullptr),
_split_check_timer(nullptr),
_split_line_timer(nullptr),
_hll_column_num(0) {
// do nothing
LOG(INFO) << "csv scan node: " << apache::thrift::ThriftDebugString(tnode).c_str();
Expand Down Expand Up @@ -589,8 +594,7 @@ bool CsvScanNode::split_check_fill(const std::string& line, RuntimeState* state)
}
}

for (std::map<std::string, TMiniLoadEtlFunction>::iterator iter = _column_function_map.begin();
iter != _column_function_map.end(); iter++) {
for (auto iter = _column_function_map.begin(); iter != _column_function_map.end(); ++iter) {
TMiniLoadEtlFunction& function = iter->second;
const std::string& column_name = iter->first;
const SlotDescriptor* slot = _column_slot_map[column_name];
Expand Down
17 changes: 11 additions & 6 deletions be/src/exec/es_scan_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ const std::string ERROR_MEM_LIMIT_EXCEEDED =
"$1 bytes for $2.";

EsScanNode::EsScanNode(ObjectPool* pool, const TPlanNode& tnode, const DescriptorTbl& descs)
: ScanNode(pool, tnode, descs), _tuple_id(tnode.es_scan_node.tuple_id), _scan_range_idx(0) {
: ScanNode(pool, tnode, descs),
_tuple_id(tnode.es_scan_node.tuple_id),
_tuple_desc(nullptr),
_env(nullptr),
_scan_range_idx(0) {
if (tnode.es_scan_node.__isset.properties) {
_properties = tnode.es_scan_node.properties;
}
Expand Down Expand Up @@ -217,7 +221,7 @@ Status EsScanNode::get_next(RuntimeState* state, RowBatch* row_batch, bool* eos)

// convert
VLOG_CRITICAL << "begin to convert: scan_range_idx=" << _scan_range_idx
<< ", num_rows=" << result.rows.num_rows;
<< ", num_rows=" << result.rows.num_rows;
std::vector<TExtColumnData>& cols = result.rows.cols;
// indexes of the next non-null value in the row batch, per column.
std::vector<int> cols_next_val_idx(_tuple_desc->slots().size(), 0);
Expand Down Expand Up @@ -420,7 +424,8 @@ bool EsScanNode::get_disjuncts(ExprContext* context, Expr* conjunct,

TExtLiteral literal;
if (!to_ext_literal(context, expr, &literal)) {
VLOG_CRITICAL << "get disjuncts fail: can't get literal, node_type=" << expr->node_type();
VLOG_CRITICAL << "get disjuncts fail: can't get literal, node_type="
<< expr->node_type();
return false;
}

Expand All @@ -446,7 +451,7 @@ bool EsScanNode::get_disjuncts(ExprContext* context, Expr* conjunct,
TExtLiteral literal;
if (!to_ext_literal(context, conjunct->get_child(1), &literal)) {
VLOG_CRITICAL << "get disjuncts fail: can't get literal, node_type="
<< conjunct->get_child(1)->node_type();
<< conjunct->get_child(1)->node_type();
return false;
}

Expand Down Expand Up @@ -497,7 +502,7 @@ bool EsScanNode::get_disjuncts(ExprContext* context, Expr* conjunct,
if (!to_ext_literal(slot_desc->type().type, const_cast<void*>(iter->get_value()),
&literal)) {
VLOG_CRITICAL << "get disjuncts fail: can't get literal, node_type="
<< slot_desc->type().type;
<< slot_desc->type().type;
return false;
}
in_pred_values.push_back(literal);
Expand All @@ -523,7 +528,7 @@ bool EsScanNode::get_disjuncts(ExprContext* context, Expr* conjunct,
return true;
} else {
VLOG_CRITICAL << "get disjuncts fail: node type is " << conjunct->node_type()
<< ", should be BINARY_PRED or COMPOUND_PRED";
<< ", should be BINARY_PRED or COMPOUND_PRED";
return false;
}
}
Expand Down
6 changes: 4 additions & 2 deletions be/src/exec/mysql_scan_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ MysqlScanNode::MysqlScanNode(ObjectPool* pool, const TPlanNode& tnode, const Des
_tuple_id(tnode.mysql_scan_node.tuple_id),
_columns(tnode.mysql_scan_node.columns),
_filters(tnode.mysql_scan_node.filters),
_tuple_desc(nullptr) {}
_tuple_desc(nullptr),
_slot_num(0) {}

MysqlScanNode::~MysqlScanNode() {}

Expand Down Expand Up @@ -136,7 +137,8 @@ Status MysqlScanNode::write_text_slot(char* value, int value_length, SlotDescrip
if (!_text_converter->write_slot(slot, _tuple, value, value_length, true, false,
_tuple_pool.get())) {
std::stringstream ss;
ss << "Fail to convert mysql value:'" << value << "' to " << slot->type() << " on column:`" << slot->col_name() + "`";
ss << "Fail to convert mysql value:'" << value << "' to " << slot->type() << " on column:`"
<< slot->col_name() + "`";
return Status::InternalError(ss.str());
}

Expand Down
6 changes: 4 additions & 2 deletions be/src/exec/odbc_scan_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ OdbcScanNode::OdbcScanNode(ObjectPool* pool, const TPlanNode& tnode, const Descr
_connect_string(std::move(tnode.odbc_scan_node.connect_string)),
_query_string(std::move(tnode.odbc_scan_node.query_string)),
_tuple_id(tnode.odbc_scan_node.tuple_id),
_tuple_desc(nullptr) {}
_tuple_desc(nullptr),
_slot_num(0) {}

OdbcScanNode::~OdbcScanNode() {}

Expand Down Expand Up @@ -115,7 +116,8 @@ Status OdbcScanNode::write_text_slot(char* value, int value_length, SlotDescript
if (!_text_converter->write_slot(slot, _tuple, value, value_length, true, false,
_tuple_pool.get())) {
std::stringstream ss;
ss << "Fail to convert odbc value:'" << value << "' to " << slot->type() << " on column:`" << slot->col_name() + "`";
ss << "Fail to convert odbc value:'" << value << "' to " << slot->type() << " on column:`"
<< slot->col_name() + "`";
return Status::InternalError(ss.str());
}

Expand Down
13 changes: 6 additions & 7 deletions be/src/exec/olap_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ OlapScanner::OlapScanner(RuntimeState* runtime_state, OlapScanNode* parent, bool
_tuple_desc(parent->_tuple_desc),
_profile(parent->runtime_profile()),
_string_slots(parent->_string_slots),
_id(-1),
_is_open(false),
_aggregation(aggregation),
_need_agg_finalize(need_agg_finalize),
_tuple_idx(parent->_tuple_idx),
_direct_conjunct_size(parent->_direct_conjunct_size),
_mem_tracker(MemTracker::CreateTracker(runtime_state->fragment_mem_tracker()->limit(),
"OlapScanner",
runtime_state->fragment_mem_tracker(),
true, true, MemTrackerLevel::DEBUG)) {
_reader.reset(new Reader());
DCHECK(_reader.get() != NULL);

_reader(new Reader()),
_version(-1),
_mem_tracker(MemTracker::CreateTracker(
runtime_state->fragment_mem_tracker()->limit(), "OlapScanner",
runtime_state->fragment_mem_tracker(), true, true, MemTrackerLevel::DEBUG)) {
_rows_read_counter = parent->rows_read_counter();
_rows_pushed_cond_filtered_counter = parent->_rows_pushed_cond_filtered_counter;
}
Expand Down
13 changes: 4 additions & 9 deletions be/src/exec/partitioned_hash_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,14 @@ Status PartitionedHashTableCtx::Init(ObjectPool* pool, RuntimeState* state, int
// TODO chenhao replace ExprContext with ScalarFnEvaluator
for (int i = 0; i < build_exprs_.size(); i++) {
ExprContext* context = pool->add(new ExprContext(build_exprs_[i]));
context->prepare(state, row_desc, tracker_);
if (context == nullptr) {
return Status::InternalError("Hashtable init error.");
}
RETURN_IF_ERROR(context->prepare(state, row_desc, tracker_));
build_expr_evals_.push_back(context);
}
DCHECK_EQ(build_exprs_.size(), build_expr_evals_.size());

for (int i = 0; i < probe_exprs_.size(); i++) {
ExprContext* context = pool->add(new ExprContext(probe_exprs_[i]));
context->prepare(state, row_desc_probe, tracker_);
if (context == nullptr) {
return Status::InternalError("Hashtable init error.");
}
RETURN_IF_ERROR(context->prepare(state, row_desc_probe, tracker_));
probe_expr_evals_.push_back(context);
}
DCHECK_EQ(probe_exprs_.size(), probe_expr_evals_.size());
Expand Down Expand Up @@ -474,7 +468,8 @@ Status PartitionedHashTable::ResizeBuckets(int64_t num_buckets,
DCHECK_GT(num_buckets, num_filled_buckets_)
<< "Cannot shrink the hash table to smaller number of buckets than the number of "
<< "filled buckets.";
VLOG_CRITICAL << "Resizing hash table from " << num_buckets_ << " to " << num_buckets << " buckets.";
VLOG_CRITICAL << "Resizing hash table from " << num_buckets_ << " to " << num_buckets
<< " buckets.";
if (max_num_buckets_ != -1 && num_buckets > max_num_buckets_) {
*got_memory = false;
return Status::OK();
Expand Down
16 changes: 8 additions & 8 deletions be/src/exec/schema_scanner/schema_charsets_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SchemaScanner::ColumnDesc SchemaCharsetsScanner::_s_css_columns[] = {

SchemaCharsetsScanner::CharsetStruct SchemaCharsetsScanner::_s_charsets[] = {
{"utf8", "utf8_general_ci", "UTF-8 Unicode", 3},
{NULL, NULL, 0},
{nullptr, nullptr, 0},
};

SchemaCharsetsScanner::SchemaCharsetsScanner()
Expand All @@ -48,7 +48,7 @@ Status SchemaCharsetsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_charsets[_index].charset);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_charsets[_index].charset, len + 1);
Expand All @@ -60,7 +60,7 @@ Status SchemaCharsetsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_charsets[_index].default_collation);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_charsets[_index].default_collation, len + 1);
Expand All @@ -72,7 +72,7 @@ Status SchemaCharsetsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_charsets[_index].description);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_charsets[_index].description, len + 1);
Expand All @@ -91,13 +91,13 @@ Status SchemaCharsetsScanner::get_next_row(Tuple* tuple, MemPool* pool, bool* eo
if (!_is_init) {
return Status::InternalError("call this before initial.");
}
if (NULL == _s_charsets[_index].charset) {
if (nullptr == tuple || nullptr == pool || nullptr == eos) {
return Status::InternalError("invalid parameter.");
}
if (nullptr == _s_charsets[_index].charset) {
*eos = true;
return Status::OK();
}
if (NULL == tuple || NULL == pool || NULL == eos) {
return Status::InternalError("invalid parameter.");
}
*eos = false;
return fill_one_row(tuple, pool);
}
Expand Down
19 changes: 10 additions & 9 deletions be/src/exec/schema_scanner/schema_collations_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SchemaScanner::ColumnDesc SchemaCollationsScanner::_s_cols_columns[] = {

SchemaCollationsScanner::CollationStruct SchemaCollationsScanner::_s_collations[] = {
{"utf8_general_ci", "utf8", 33, "Yes", "Yes", 1},
{NULL, NULL, 0, NULL, NULL, 0},
{nullptr, nullptr, 0, nullptr, nullptr, 0},
};

SchemaCollationsScanner::SchemaCollationsScanner()
Expand All @@ -51,7 +51,7 @@ Status SchemaCollationsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_collations[_index].name);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_collations[_index].name, len + 1);
Expand All @@ -63,7 +63,7 @@ Status SchemaCollationsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_collations[_index].charset);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_collations[_index].charset, len + 1);
Expand All @@ -80,7 +80,7 @@ Status SchemaCollationsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_collations[_index].is_default);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_collations[_index].is_default, len + 1);
Expand All @@ -92,7 +92,7 @@ Status SchemaCollationsScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_s_collations[_index].is_compile);
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _s_collations[_index].is_compile, len + 1);
Expand All @@ -111,13 +111,14 @@ Status SchemaCollationsScanner::get_next_row(Tuple* tuple, MemPool* pool, bool*
if (!_is_init) {
return Status::InternalError("call this before initial.");
}
if (NULL == _s_collations[_index].name) {
if (nullptr == tuple || nullptr == pool || nullptr == eos) {
return Status::InternalError("invalid parameter.");
}
if (nullptr == _s_collations[_index].name) {
*eos = true;
return Status::OK();
}
if (NULL == tuple || NULL == pool || NULL == eos) {
return Status::InternalError("invalid parameter.");
}

*eos = false;
return fill_one_row(tuple, pool);
}
Expand Down
12 changes: 6 additions & 6 deletions be/src/exec/schema_scanner/schema_variables_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Status SchemaVariablesScanner::start(RuntimeState* state) {
}
var_params.__set_threadId(_param->thread_id);

if (NULL != _param->ip && 0 != _param->port) {
if (nullptr != _param->ip && 0 != _param->port) {
RETURN_IF_ERROR(SchemaHelper::show_variables(*(_param->ip), _param->port, var_params,
&_var_result));
} else {
Expand All @@ -68,7 +68,7 @@ Status SchemaVariablesScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_begin->first.c_str());
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _begin->first.c_str(), len + 1);
Expand All @@ -80,7 +80,7 @@ Status SchemaVariablesScanner::fill_one_row(Tuple* tuple, MemPool* pool) {
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
int len = strlen(_begin->second.c_str());
str_slot->ptr = (char*)pool->allocate(len + 1);
if (NULL == str_slot->ptr) {
if (nullptr == str_slot->ptr) {
return Status::InternalError("No Memory.");
}
memcpy(str_slot->ptr, _begin->second.c_str(), len + 1);
Expand All @@ -94,13 +94,13 @@ Status SchemaVariablesScanner::get_next_row(Tuple* tuple, MemPool* pool, bool* e
if (!_is_init) {
return Status::InternalError("call this before initial.");
}
if (nullptr == tuple || nullptr == pool || nullptr == eos) {
return Status::InternalError("invalid parameter.");
}
if (_begin == _var_result.variables.end()) {
*eos = true;
return Status::OK();
}
if (NULL == tuple || NULL == pool || NULL == eos) {
return Status::InternalError("invalid parameter.");
}
*eos = false;
return fill_one_row(tuple, pool);
}
Expand Down
Loading

0 comments on commit f70b55f

Please sign in to comment.