Merge pull request #24509 from taosdata/fix/xsren/TD-28327/doubleFormat3.0
fix: LEASTSQUARES func result stack overflow
This commit is contained in:
commit
567aab933d
|
@ -249,6 +249,10 @@ typedef struct SPoint {
|
|||
int32_t taosGetLinearInterpolationVal(SPoint *point, int32_t outputType, SPoint *point1, SPoint *point2,
|
||||
int32_t inputType);
|
||||
|
||||
#define LEASTSQUARES_DOUBLE_ITEM_LENGTH 25
|
||||
#define LEASTSQUARES_BUFF_LENGTH 128
|
||||
#define DOUBLE_PRECISION_DIGITS "16e"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1576,9 +1576,19 @@ int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
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 =
|
||||
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);
|
||||
|
||||
colDataSetVal(pCol, currentRow, buf, pResInfo->isNullRes);
|
||||
|
|
|
@ -2427,9 +2427,19 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa
|
|||
|
||||
matrix12 /= matrix[1][1];
|
||||
|
||||
char buf[64] = {0};
|
||||
size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02,
|
||||
matrix12);
|
||||
char buf[LEASTSQUARES_BUFF_LENGTH] = {0};
|
||||
char slopBuf[64] = {0};
|
||||
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);
|
||||
colDataSetVal(pOutputData, 0, buf, false);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue