提交 e0dbe221 编写于 作者: H Haojun Liao

fix(query): fix uninitialized memory buffer accessed.

上级 75f4e643
......@@ -41,6 +41,12 @@ typedef struct SBlockOrderInfo {
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
} while (0)
#define colDataSetNull_f_s(c_, r_) \
do { \
colDataSetNull_f((c_)->nullbitmap, r_); \
memset(((char*)(c_)->pData) + (c_)->info.bytes * (r_), 0, (c_)->info.bytes); \
} while (0)
#define colDataClearNull_f(bm_, r_) \
do { \
BMCharPos(bm_, r_) &= ((char)(~(1u << (7u - BitPos(r_))))); \
......@@ -136,7 +142,7 @@ static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uin
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
colDataSetNull_var(pColumnInfoData, currentRow); // it is a null value of VAR type.
} else {
colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow);
colDataSetNull_f_s(pColumnInfoData, currentRow);
}
pColumnInfoData->hasNull = true;
......@@ -151,6 +157,7 @@ static FORCE_INLINE void colDataAppendNNULL(SColumnInfoData* pColumnInfoData, ui
for (int32_t i = start; i < start + nRows; ++i) {
colDataSetNull_f(pColumnInfoData->nullbitmap, i);
}
memset(pColumnInfoData->pData + start * pColumnInfoData->info.bytes, 0, pColumnInfoData->info.bytes * nRows);
}
pColumnInfoData->hasNull = true;
......
......@@ -69,7 +69,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type.
} else {
colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow);
colDataSetNull_f_s(pColumnInfoData, currentRow);
}
pColumnInfoData->hasNull = true;
......@@ -825,7 +825,7 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB
} else {
for (int32_t j = 0; j < pDataBlock->info.rows; ++j) {
if (colDataIsNull_f(pSrc->nullbitmap, index[j])) {
colDataSetNull_f(pDst->nullbitmap, j);
colDataSetNull_f_s(pDst, j);
continue;
}
memcpy(pDst->pData + j * pDst->info.bytes, pSrc->pData + index[j] * pDst->info.bytes, pDst->info.bytes);
......
......@@ -279,7 +279,6 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
// for stream interval
if (pBlock->info.type == STREAM_RETRIEVE || pBlock->info.type == STREAM_DELETE_RESULT ||
pBlock->info.type == STREAM_DELETE_DATA) {
// printDataBlock1(pBlock, "project1");
return pBlock;
}
......
......@@ -1918,6 +1918,13 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
colDataAppend(pColInfo, 0, p, false);
taosMemoryFree(p);
// make the valgrind happy that all memory buffer has been initialized already.
if (slotId != 0) {
SColumnInfoData* p1 = taosArrayGet(pBlock->pDataBlock, 0);
int64_t v = 0;
colDataAppendInt64(p1, 0, &v);
}
pBlock->info.rows = 1;
pOperator->status = OP_EXEC_DONE;
return pBlock;
......
......@@ -2645,7 +2645,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
int32_t v = *(int32_t*)pv;
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
if (delta < 0 && pDiffInfo->ignoreNegative) {
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
} else {
colDataAppendInt64(pOutput, pos, &delta);
}
......@@ -2658,7 +2658,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
int8_t v = *(int8_t*)pv;
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
if (delta < 0 && pDiffInfo->ignoreNegative) {
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
} else {
colDataAppendInt64(pOutput, pos, &delta);
}
......@@ -2669,7 +2669,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
int16_t v = *(int16_t*)pv;
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
if (delta < 0 && pDiffInfo->ignoreNegative) {
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
} else {
colDataAppendInt64(pOutput, pos, &delta);
}
......@@ -2681,7 +2681,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
int64_t v = *(int64_t*)pv;
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
if (delta < 0 && pDiffInfo->ignoreNegative) {
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
} else {
colDataAppendInt64(pOutput, pos, &delta);
}
......@@ -2692,7 +2692,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
float v = *(float*)pv;
double delta = factor * (v - pDiffInfo->prev.d64); // direct previous may be null
if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { // check for overflow
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
} else {
colDataAppendDouble(pOutput, pos, &delta);
}
......@@ -2703,7 +2703,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
double v = *(double*)pv;
double delta = factor * (v - pDiffInfo->prev.d64); // direct previous may be null
if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { // check for overflow
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
} else {
colDataAppendDouble(pOutput, pos, &delta);
}
......@@ -2738,7 +2738,7 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
if (pDiffInfo->includeNull) {
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
numOfElems += 1;
}
......@@ -2776,8 +2776,7 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
if (pDiffInfo->includeNull) {
colDataSetNull_f(pOutput->nullbitmap, pos);
colDataSetNull_f_s(pOutput, pos);
numOfElems += 1;
}
continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册