fix: LEASTSQUARES func result stack overflow
This commit is contained in:
parent
fc16d26da2
commit
f010e18ff0
|
@ -249,6 +249,10 @@ typedef struct SPoint {
|
||||||
int32_t taosGetLinearInterpolationVal(SPoint *point, int32_t outputType, SPoint *point1, SPoint *point2,
|
int32_t taosGetLinearInterpolationVal(SPoint *point, int32_t outputType, SPoint *point1, SPoint *point2,
|
||||||
int32_t inputType);
|
int32_t inputType);
|
||||||
|
|
||||||
|
#define LEASTSQUARES_DOUBLE_ITEM_LENGTH 25
|
||||||
|
#define LEASTSQUARES_BUFF_LENGTH 128
|
||||||
|
#define DOUBLE_PRECISION_DIGITS "16e"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -952,7 +952,7 @@ static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pFunc->node.resType = (SDataType){.bytes = 64, .type = TSDB_DATA_TYPE_BINARY};
|
pFunc->node.resType = (SDataType){.bytes = LEASTSQUARES_BUFF_LENGTH, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1576,9 +1576,19 @@ int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
|
||||||
param12 /= param[1][1];
|
param12 /= param[1][1];
|
||||||
|
|
||||||
char buf[512] = {0};
|
char buf[LEASTSQUARES_BUFF_LENGTH] = {0};
|
||||||
|
char slopBuf[64] = {0};
|
||||||
|
char interceptBuf[64] = {0};
|
||||||
|
int n = snprintf(slopBuf, 64, "%.6lf", param02);
|
||||||
|
if (n > LEASTSQUARES_DOUBLE_ITEM_LENGTH) {
|
||||||
|
snprintf(slopBuf, 64, "%." DOUBLE_PRECISION_DIGITS, param02);
|
||||||
|
}
|
||||||
|
n = snprintf(interceptBuf, 64, "%.6lf", param12);
|
||||||
|
if (n > LEASTSQUARES_DOUBLE_ITEM_LENGTH) {
|
||||||
|
snprintf(interceptBuf, 64, "%." DOUBLE_PRECISION_DIGITS, param12);
|
||||||
|
}
|
||||||
size_t len =
|
size_t len =
|
||||||
snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", param02, param12);
|
snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%s, intercept:%s}", slopBuf, interceptBuf);
|
||||||
varDataSetLen(buf, len);
|
varDataSetLen(buf, len);
|
||||||
|
|
||||||
colDataSetVal(pCol, currentRow, buf, pResInfo->isNullRes);
|
colDataSetVal(pCol, currentRow, buf, pResInfo->isNullRes);
|
||||||
|
|
|
@ -2427,9 +2427,19 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
|
||||||
|
|
||||||
matrix12 /= matrix[1][1];
|
matrix12 /= matrix[1][1];
|
||||||
|
|
||||||
char buf[64] = {0};
|
char buf[LEASTSQUARES_BUFF_LENGTH] = {0};
|
||||||
size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02,
|
char slopBuf[64] = {0};
|
||||||
matrix12);
|
char interceptBuf[64] = {0};
|
||||||
|
int n = snprintf(slopBuf, 64, "%.6lf", matrix02);
|
||||||
|
if (n > LEASTSQUARES_DOUBLE_ITEM_LENGTH) {
|
||||||
|
snprintf(slopBuf, 64, "%." DOUBLE_PRECISION_DIGITS, matrix02);
|
||||||
|
}
|
||||||
|
n = snprintf(interceptBuf, 64, "%.6lf", matrix12);
|
||||||
|
if (n > LEASTSQUARES_DOUBLE_ITEM_LENGTH) {
|
||||||
|
snprintf(interceptBuf, 64, "%." DOUBLE_PRECISION_DIGITS, matrix12);
|
||||||
|
}
|
||||||
|
size_t len =
|
||||||
|
snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%s, intercept:%s}", slopBuf, interceptBuf);
|
||||||
varDataSetLen(buf, len);
|
varDataSetLen(buf, len);
|
||||||
colDataSetVal(pOutputData, 0, buf, false);
|
colDataSetVal(pOutputData, 0, buf, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue