fix(query): fix uninitialized memory buffer accessed.
This commit is contained in:
parent
75f4e64326
commit
e0dbe22199
|
@ -41,6 +41,12 @@ typedef struct SBlockOrderInfo {
|
||||||
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
|
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
|
||||||
} while (0)
|
} 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_) \
|
#define colDataClearNull_f(bm_, r_) \
|
||||||
do { \
|
do { \
|
||||||
BMCharPos(bm_, r_) &= ((char)(~(1u << (7u - BitPos(r_))))); \
|
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)) {
|
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||||
colDataSetNull_var(pColumnInfoData, currentRow); // it is a null value of VAR type.
|
colDataSetNull_var(pColumnInfoData, currentRow); // it is a null value of VAR type.
|
||||||
} else {
|
} else {
|
||||||
colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow);
|
colDataSetNull_f_s(pColumnInfoData, currentRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pColumnInfoData->hasNull = true;
|
pColumnInfoData->hasNull = true;
|
||||||
|
@ -151,6 +157,7 @@ static FORCE_INLINE void colDataAppendNNULL(SColumnInfoData* pColumnInfoData, ui
|
||||||
for (int32_t i = start; i < start + nRows; ++i) {
|
for (int32_t i = start; i < start + nRows; ++i) {
|
||||||
colDataSetNull_f(pColumnInfoData->nullbitmap, i);
|
colDataSetNull_f(pColumnInfoData->nullbitmap, i);
|
||||||
}
|
}
|
||||||
|
memset(pColumnInfoData->pData + start * pColumnInfoData->info.bytes, 0, pColumnInfoData->info.bytes * nRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
pColumnInfoData->hasNull = true;
|
pColumnInfoData->hasNull = true;
|
||||||
|
|
|
@ -69,7 +69,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
||||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||||
pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type.
|
pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type.
|
||||||
} else {
|
} else {
|
||||||
colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow);
|
colDataSetNull_f_s(pColumnInfoData, currentRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pColumnInfoData->hasNull = true;
|
pColumnInfoData->hasNull = true;
|
||||||
|
@ -825,7 +825,7 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB
|
||||||
} else {
|
} else {
|
||||||
for (int32_t j = 0; j < pDataBlock->info.rows; ++j) {
|
for (int32_t j = 0; j < pDataBlock->info.rows; ++j) {
|
||||||
if (colDataIsNull_f(pSrc->nullbitmap, index[j])) {
|
if (colDataIsNull_f(pSrc->nullbitmap, index[j])) {
|
||||||
colDataSetNull_f(pDst->nullbitmap, j);
|
colDataSetNull_f_s(pDst, j);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
memcpy(pDst->pData + j * pDst->info.bytes, pSrc->pData + index[j] * pDst->info.bytes, pDst->info.bytes);
|
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
|
// for stream interval
|
||||||
if (pBlock->info.type == STREAM_RETRIEVE || pBlock->info.type == STREAM_DELETE_RESULT ||
|
if (pBlock->info.type == STREAM_RETRIEVE || pBlock->info.type == STREAM_DELETE_RESULT ||
|
||||||
pBlock->info.type == STREAM_DELETE_DATA) {
|
pBlock->info.type == STREAM_DELETE_DATA) {
|
||||||
// printDataBlock1(pBlock, "project1");
|
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1918,6 +1918,13 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
|
||||||
colDataAppend(pColInfo, 0, p, false);
|
colDataAppend(pColInfo, 0, p, false);
|
||||||
taosMemoryFree(p);
|
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;
|
pBlock->info.rows = 1;
|
||||||
pOperator->status = OP_EXEC_DONE;
|
pOperator->status = OP_EXEC_DONE;
|
||||||
return pBlock;
|
return pBlock;
|
||||||
|
|
|
@ -2645,7 +2645,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
|
||||||
int32_t v = *(int32_t*)pv;
|
int32_t v = *(int32_t*)pv;
|
||||||
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
||||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
} else {
|
} else {
|
||||||
colDataAppendInt64(pOutput, pos, &delta);
|
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;
|
int8_t v = *(int8_t*)pv;
|
||||||
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
||||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
} else {
|
} else {
|
||||||
colDataAppendInt64(pOutput, pos, &delta);
|
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;
|
int16_t v = *(int16_t*)pv;
|
||||||
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
||||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
} else {
|
} else {
|
||||||
colDataAppendInt64(pOutput, pos, &delta);
|
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 v = *(int64_t*)pv;
|
||||||
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
int64_t delta = factor * (v - pDiffInfo->prev.i64); // direct previous may be null
|
||||||
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
if (delta < 0 && pDiffInfo->ignoreNegative) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
} else {
|
} else {
|
||||||
colDataAppendInt64(pOutput, pos, &delta);
|
colDataAppendInt64(pOutput, pos, &delta);
|
||||||
}
|
}
|
||||||
|
@ -2692,7 +2692,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
|
||||||
float v = *(float*)pv;
|
float v = *(float*)pv;
|
||||||
double delta = factor * (v - pDiffInfo->prev.d64); // direct previous may be null
|
double delta = factor * (v - pDiffInfo->prev.d64); // direct previous may be null
|
||||||
if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { // check for overflow
|
if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { // check for overflow
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
} else {
|
} else {
|
||||||
colDataAppendDouble(pOutput, pos, &delta);
|
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 v = *(double*)pv;
|
||||||
double delta = factor * (v - pDiffInfo->prev.d64); // direct previous may be null
|
double delta = factor * (v - pDiffInfo->prev.d64); // direct previous may be null
|
||||||
if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { // check for overflow
|
if ((delta < 0 && pDiffInfo->ignoreNegative) || isinf(delta) || isnan(delta)) { // check for overflow
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
} else {
|
} else {
|
||||||
colDataAppendDouble(pOutput, pos, &delta);
|
colDataAppendDouble(pOutput, pos, &delta);
|
||||||
}
|
}
|
||||||
|
@ -2738,7 +2738,7 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
if (pDiffInfo->includeNull) {
|
if (pDiffInfo->includeNull) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
|
|
||||||
numOfElems += 1;
|
numOfElems += 1;
|
||||||
}
|
}
|
||||||
|
@ -2776,8 +2776,7 @@ int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
|
||||||
if (pDiffInfo->includeNull) {
|
if (pDiffInfo->includeNull) {
|
||||||
colDataSetNull_f(pOutput->nullbitmap, pos);
|
colDataSetNull_f_s(pOutput, pos);
|
||||||
|
|
||||||
numOfElems += 1;
|
numOfElems += 1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue