未验证 提交 4b4f8eac 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #18184 from taosdata/fix/TD-20403

fix(query): fix signed integer overflow in builtinsimpl.c
...@@ -2139,6 +2139,11 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { ...@@ -2139,6 +2139,11 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t type = pStddevRes->type; int32_t type = pStddevRes->type;
double avg; double avg;
if (pStddevRes->count == 0) {
GET_RES_INFO(pCtx)->numOfRes = 0;
return functionFinalize(pCtx, pBlock);
}
if (IS_SIGNED_NUMERIC_TYPE(type)) { if (IS_SIGNED_NUMERIC_TYPE(type)) {
avg = pStddevRes->isum / ((double)pStddevRes->count); avg = pStddevRes->isum / ((double)pStddevRes->count);
pStddevRes->result = sqrt(fabs(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg)); pStddevRes->result = sqrt(fabs(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg));
...@@ -5708,6 +5713,10 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { ...@@ -5708,6 +5713,10 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
} }
static double twa_get_area(SPoint1 s, SPoint1 e) { static double twa_get_area(SPoint1 s, SPoint1 e) {
if (e.key == INT64_MAX || s.key == INT64_MIN) {
return 0;
}
if ((s.val >= 0 && e.val >= 0) || (s.val <= 0 && e.val <= 0)) { if ((s.val >= 0 && e.val >= 0) || (s.val <= 0 && e.val <= 0)) {
return (s.val + e.val) * (e.key - s.key) / 2; return (s.val + e.val) * (e.key - s.key) / 2;
} }
...@@ -6002,6 +6011,8 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { ...@@ -6002,6 +6011,8 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
} else { } else {
if (pInfo->win.ekey == pInfo->win.skey) { if (pInfo->win.ekey == pInfo->win.skey) {
pInfo->dOutput = pInfo->p.val; pInfo->dOutput = pInfo->p.val;
} else if (pInfo->win.ekey == INT64_MAX || pInfo->win.skey == INT64_MIN) { //no data in timewindow
pInfo->dOutput = 0;
} else { } else {
pInfo->dOutput = pInfo->dOutput / (pInfo->win.ekey - pInfo->win.skey); pInfo->dOutput = pInfo->dOutput / (pInfo->win.ekey - pInfo->win.skey);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册