Merge pull request #28131 from taosdata/enh/TD-32203/taosndup
taosStrndup
This commit is contained in:
commit
c7c9e2c8cf
|
@ -76,7 +76,6 @@ typedef int (*__compar_fn_t)(const void *, const void *);
|
|||
|
||||
char *strsep(char **stringp, const char *delim);
|
||||
char *getpass(const char *prefix);
|
||||
char *strndup(const char *s, int n);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
|
|
|
@ -51,6 +51,7 @@ typedef enum { M2C = 0, C2M } ConvType;
|
|||
#define strtod STR_TO_LD_FUNC_TAOS_FORBID
|
||||
#define strtold STR_TO_D_FUNC_TAOS_FORBID
|
||||
#define strtof STR_TO_F_FUNC_TAOS_FORBID
|
||||
#define strndup STR_TO_F_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
|
@ -101,8 +102,9 @@ int8_t taosStr2Int8(const char *str, char **pEnd, int32_t radix);
|
|||
uint8_t taosStr2UInt8(const char *str, char **pEnd, int32_t radix);
|
||||
double taosStr2Double(const char *str, char **pEnd);
|
||||
float taosStr2Float(const char *str, char **pEnd);
|
||||
int32_t taosHex2Ascii(const char *z, uint32_t n, void** data, uint32_t* size);
|
||||
int32_t taosAscii2Hex(const char *z, uint32_t n, void** data, uint32_t* size);
|
||||
int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size);
|
||||
int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size);
|
||||
char *taosStrndup(const char *s, int n);
|
||||
//int32_t taosBin2Ascii(const char *z, uint32_t n, void** data, uint32_t* size);
|
||||
bool isHex(const char* z, uint32_t n);
|
||||
bool isValidateHex(const char* z, uint32_t n);
|
||||
|
|
|
@ -2441,10 +2441,9 @@ char* getDbOfConnection(STscObj* pObj) {
|
|||
(void)taosThreadMutexLock(&pObj->mutex);
|
||||
size_t len = strlen(pObj->db);
|
||||
if (len > 0) {
|
||||
p = strndup(pObj->db, tListLen(pObj->db));
|
||||
p = taosStrndup(pObj->db, tListLen(pObj->db));
|
||||
if (p == NULL) {
|
||||
tscError("failed to strndup db name");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tscError("failed to taosStrndup db name");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -923,9 +923,9 @@ int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
|
|||
length = strlen(sql);
|
||||
}
|
||||
|
||||
pStmt->sql.sqlStr = strndup(sql, length);
|
||||
pStmt->sql.sqlStr = taosStrndup(sql, length);
|
||||
if (!pStmt->sql.sqlStr) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
pStmt->sql.sqlLen = length;
|
||||
pStmt->sql.stbInterlaceMode = pStmt->stbInterlaceMode;
|
||||
|
|
|
@ -874,9 +874,9 @@ int stmtPrepare2(TAOS_STMT2* stmt, const char* sql, unsigned long length) {
|
|||
length = strlen(sql);
|
||||
}
|
||||
|
||||
pStmt->sql.sqlStr = strndup(sql, length);
|
||||
pStmt->sql.sqlStr = taosStrndup(sql, length);
|
||||
if (!pStmt->sql.sqlStr) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
pStmt->sql.sqlLen = length;
|
||||
pStmt->sql.stbInterlaceMode = pStmt->stbInterlaceMode;
|
||||
|
|
|
@ -316,6 +316,7 @@ int32_t doKillCheckpointTrans(SMnode *pMnode, const char *pDBName, size_t len) {
|
|||
// kill all trans in the dst DB
|
||||
void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo) {
|
||||
mDebug("start to clear checkpoints in all Dbs");
|
||||
char p[128] = {0};
|
||||
|
||||
void *pIter = NULL;
|
||||
while ((pIter = taosHashIterate(pChangeInfo->pDBMap, pIter)) != NULL) {
|
||||
|
@ -323,15 +324,14 @@ void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo) {
|
|||
|
||||
size_t len = 0;
|
||||
void *pKey = taosHashGetKey(pDb, &len);
|
||||
char *p = strndup(pKey, len);
|
||||
tstrncpy(p, pKey, 128);
|
||||
|
||||
int32_t code = doKillCheckpointTrans(pMnode, pKey, len);
|
||||
if (code) {
|
||||
mError("failed to kill trans, transId:%p", pKey)
|
||||
mError("failed to kill trans, transId:%p", pKey);
|
||||
} else {
|
||||
mDebug("clear checkpoint trans in Db:%s", p);
|
||||
}
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
|
||||
mDebug("complete clear checkpoints in all Dbs");
|
||||
|
|
|
@ -333,14 +333,14 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC
|
|||
continue;
|
||||
}
|
||||
|
||||
int32_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET);
|
||||
int64_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
releaseFdToFileCtx(pFd);
|
||||
code = terrno;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
ret = (int32_t)taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize);
|
||||
ret = taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize);
|
||||
if (ret != pHead->basic.bufSize) {
|
||||
releaseFdToFileCtx(pFd);
|
||||
code = terrno;
|
||||
|
@ -578,7 +578,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa
|
|||
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
int32_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET);
|
||||
int64_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
code = terrno;
|
||||
goto _return;
|
||||
|
@ -590,7 +590,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa
|
|||
goto _return;
|
||||
}
|
||||
|
||||
ret = (int32_t)taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize);
|
||||
ret = taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize);
|
||||
if (ret != pBasic->bufSize) {
|
||||
taosMemoryFreeClear(*ppBuf);
|
||||
code = terrno;
|
||||
|
|
|
@ -222,10 +222,10 @@ static int32_t addTimezoneParam(SNodeList* pList) {
|
|||
return code;
|
||||
}
|
||||
|
||||
pVal->literal = strndup(buf, len);
|
||||
pVal->literal = taosStrndup(buf, len);
|
||||
if (pVal->literal == NULL) {
|
||||
nodesDestroyNode((SNode*)pVal);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
pVal->translate = true;
|
||||
pVal->node.resType.type = TSDB_DATA_TYPE_BINARY;
|
||||
|
|
|
@ -4838,9 +4838,9 @@ int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResul
|
|||
pInfo->totalCount = 0;
|
||||
pInfo->normalized = 0;
|
||||
|
||||
char* binTypeStr = strndup(varDataVal(pCtx->param[1].param.pz), varDataLen(pCtx->param[1].param.pz));
|
||||
char* binTypeStr = taosStrndup(varDataVal(pCtx->param[1].param.pz), varDataLen(pCtx->param[1].param.pz));
|
||||
if (binTypeStr == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
int8_t binType = getHistogramBinType(binTypeStr);
|
||||
taosMemoryFree(binTypeStr);
|
||||
|
@ -4848,9 +4848,9 @@ int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResul
|
|||
if (binType == UNKNOWN_BIN) {
|
||||
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
}
|
||||
char* binDesc = strndup(varDataVal(pCtx->param[2].param.pz), varDataLen(pCtx->param[2].param.pz));
|
||||
char* binDesc = taosStrndup(varDataVal(pCtx->param[2].param.pz), varDataLen(pCtx->param[2].param.pz));
|
||||
if (binDesc == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
int64_t normalized = pCtx->param[3].param.i;
|
||||
if (normalized != 0 && normalized != 1) {
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct IFileCtx {
|
|||
int (*write)(struct IFileCtx* ctx, uint8_t* buf, int len);
|
||||
int (*read)(struct IFileCtx* ctx, uint8_t* buf, int len);
|
||||
int (*flush)(struct IFileCtx* ctx);
|
||||
int (*readFrom)(struct IFileCtx* ctx, uint8_t* buf, int len, int32_t offset);
|
||||
int64_t (*readFrom)(struct IFileCtx* ctx, uint8_t* buf, int len, int32_t offset);
|
||||
int (*size)(struct IFileCtx* ctx);
|
||||
|
||||
SLRUCache* lru;
|
||||
|
@ -64,7 +64,7 @@ typedef struct IFileCtx {
|
|||
|
||||
static int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len);
|
||||
static int idxFileCtxDoRead(IFileCtx* ctx, uint8_t* buf, int len);
|
||||
static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset);
|
||||
static int64_t idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset);
|
||||
static int idxFileCtxDoFlush(IFileCtx* ctx);
|
||||
|
||||
IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity);
|
||||
|
|
|
@ -362,21 +362,19 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
|
|||
if (colVal != NULL && nColVal != 0) {
|
||||
len = idxConvertDataToStr((void*)colVal, IDX_TYPE_GET_TYPE(colType), (void**)&buf);
|
||||
} else if (colVal == NULL) {
|
||||
buf = strndup(INDEX_DATA_NULL_STR, (int32_t)strlen(INDEX_DATA_NULL_STR));
|
||||
buf = taosStrndup(INDEX_DATA_NULL_STR, (int32_t)strlen(INDEX_DATA_NULL_STR));
|
||||
if (buf == NULL) {
|
||||
taosMemoryFree(tm->colName);
|
||||
taosMemoryFree(tm);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
len = (int32_t)strlen(INDEX_DATA_NULL_STR);
|
||||
} else {
|
||||
static const char* emptyStr = " ";
|
||||
buf = strndup(emptyStr, (int32_t)strlen(emptyStr));
|
||||
buf = taosStrndup(emptyStr, (int32_t)strlen(emptyStr));
|
||||
if (buf == NULL) {
|
||||
taosMemoryFree(tm->colName);
|
||||
taosMemoryFree(tm);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
len = (int32_t)strlen(emptyStr);
|
||||
|
@ -386,7 +384,6 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
|
|||
if (tm->colVal == NULL) {
|
||||
taosMemoryFree(tm->colName);
|
||||
taosMemoryFree(tm);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -345,9 +345,9 @@ int idxUidCompare(const void* a, const void* b) {
|
|||
|
||||
int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) {
|
||||
if (src == NULL) {
|
||||
*dst = strndup(INDEX_DATA_NULL_STR, (int)strlen(INDEX_DATA_NULL_STR));
|
||||
*dst = taosStrndup(INDEX_DATA_NULL_STR, (int)strlen(INDEX_DATA_NULL_STR));
|
||||
if (*dst == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
return (int32_t)strlen(INDEX_DATA_NULL_STR);
|
||||
}
|
||||
|
|
|
@ -96,8 +96,8 @@ static FORCE_INLINE int idxFileCtxDoRead(IFileCtx* ctx, uint8_t* buf, int len) {
|
|||
|
||||
return nRead;
|
||||
}
|
||||
static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset) {
|
||||
int32_t total = 0, nread = 0;
|
||||
static int64_t idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t offset) {
|
||||
int64_t total = 0, nread = 0;
|
||||
int32_t blkId = offset / kBlockSize;
|
||||
int32_t blkOffset = offset % kBlockSize;
|
||||
int32_t blkLeft = kBlockSize - blkOffset;
|
||||
|
@ -122,7 +122,7 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
|
|||
int32_t left = ctx->file.size - offset;
|
||||
if (left < kBlockSize) {
|
||||
nread = TMIN(left, len);
|
||||
int32_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset);
|
||||
int64_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset);
|
||||
if (bytes != nread) {
|
||||
total = TSDB_CODE_INDEX_INVALID_FILE;
|
||||
break;
|
||||
|
|
|
@ -45,7 +45,7 @@ static int tfileWriteFooter(TFileWriter* write);
|
|||
|
||||
// handle file corrupt later
|
||||
static int tfileReaderLoadHeader(TFileReader* reader);
|
||||
static int tfileReaderLoadFst(TFileReader* reader);
|
||||
static int32_t tfileReaderLoadFst(TFileReader* reader);
|
||||
static int tfileReaderVerify(TFileReader* reader);
|
||||
static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result);
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
|
|||
|
||||
int64_t nread = reader->ctx->readFrom(reader->ctx, (uint8_t*)buf, sizeof(buf), 0);
|
||||
|
||||
if (nread == -1) {
|
||||
if (nread < 0) {
|
||||
indexError("actual Read: %d, to read: %d, code:0x%x, filename: %s", (int)(nread), (int)sizeof(buf), errno,
|
||||
reader->ctx->file.buf);
|
||||
} else {
|
||||
|
@ -1032,7 +1032,7 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
static int tfileReaderLoadFst(TFileReader* reader) {
|
||||
static int32_t tfileReaderLoadFst(TFileReader* reader) {
|
||||
IFileCtx* ctx = reader->ctx;
|
||||
int size = ctx->size(ctx);
|
||||
|
||||
|
@ -1040,7 +1040,7 @@ static int tfileReaderLoadFst(TFileReader* reader) {
|
|||
int fstSize = size - reader->header.fstOffset - sizeof(FILE_MAGIC_NUMBER);
|
||||
char* buf = taosMemoryCalloc(1, fstSize);
|
||||
if (buf == NULL) {
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int64_t ts = taosGetTimestampUs();
|
||||
|
@ -1058,7 +1058,7 @@ static int tfileReaderLoadFst(TFileReader* reader) {
|
|||
taosMemoryFree(buf);
|
||||
fstSliceDestroy(&st);
|
||||
|
||||
return reader->fst != NULL ? 0 : -1;
|
||||
return reader->fst != NULL ? 0 : TSDB_CODE_INDEX_INVALID_FILE;
|
||||
}
|
||||
static int32_t tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result) {
|
||||
// TODO(yihao): opt later
|
||||
|
@ -1067,7 +1067,7 @@ static int32_t tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArr
|
|||
IFileCtx* ctx = reader->ctx;
|
||||
// add block cache
|
||||
char block[4096] = {0};
|
||||
int32_t nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset);
|
||||
int64_t nread = ctx->readFrom(ctx, (uint8_t*)block, sizeof(block), offset);
|
||||
if (nread < sizeof(uint32_t)) {
|
||||
return TSDB_CODE_INDEX_INVALID_FILE;
|
||||
}
|
||||
|
|
|
@ -513,8 +513,8 @@ static int32_t tlvDecodeValueCStr(STlvDecoder* pDecoder, char* pValue) {
|
|||
}
|
||||
|
||||
static int32_t tlvDecodeCStrP(STlv* pTlv, char** pValue) {
|
||||
*pValue = strndup(pTlv->value, pTlv->len);
|
||||
return NULL == *pValue ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS;
|
||||
*pValue = taosStrndup(pTlv->value, pTlv->len);
|
||||
return NULL == *pValue ? terrno : TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tlvDecodeDynBinary(STlv* pTlv, void** pValue) {
|
||||
|
|
|
@ -404,9 +404,9 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
|
|||
SValueNode* val = NULL;
|
||||
pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
|
||||
CHECK_MAKE_NODE(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
val->literal = taosStrndup(pLiteral->z, pLiteral->n);
|
||||
if(!val->literal) {
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pCxt->errCode = terrno;
|
||||
nodesDestroyNode((SNode*)val);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -434,14 +434,22 @@ SNode* createRawValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToke
|
|||
goto _exit;
|
||||
}
|
||||
if (pLiteral) {
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
val->literal = taosStrndup(pLiteral->z, pLiteral->n);
|
||||
if (!val->literal) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, terrno, "Out of memory");
|
||||
goto _exit;
|
||||
}
|
||||
} else if (pNode) {
|
||||
SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
|
||||
if (!nodesIsExprNode(pRawExpr->pNode)) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pRawExpr->p);
|
||||
goto _exit;
|
||||
}
|
||||
val->literal = strndup(pRawExpr->p, pRawExpr->n);
|
||||
val->literal = taosStrndup(pRawExpr->p, pRawExpr->n);
|
||||
if (!val->literal) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, terrno, "Out of memory");
|
||||
goto _exit;
|
||||
}
|
||||
} else {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTERNAL_ERROR, "Invalid parameters");
|
||||
goto _exit;
|
||||
|
@ -479,8 +487,8 @@ SNode* createRawValueNodeExt(SAstCreateContext* pCxt, int32_t dataType, const ST
|
|||
goto _exit;
|
||||
}
|
||||
if (pLiteral) {
|
||||
if (!(val->literal = strndup(pLiteral->z, pLiteral->n))) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY, "Out of memory");
|
||||
if (!(val->literal = taosStrndup(pLiteral->z, pLiteral->n))) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, terrno, "Out of memory");
|
||||
goto _exit;
|
||||
}
|
||||
} else {
|
||||
|
@ -579,7 +587,7 @@ SNodeList* createHintNodeList(SAstCreateContext* pCxt, const SToken* pLiteral) {
|
|||
return NULL;
|
||||
}
|
||||
SNodeList* pHintList = NULL;
|
||||
char* hint = strndup(pLiteral->z + 3, pLiteral->n - 5);
|
||||
char* hint = taosStrndup(pLiteral->z + 3, pLiteral->n - 5);
|
||||
if (!hint) return NULL;
|
||||
int32_t i = 0;
|
||||
bool quit = false;
|
||||
|
@ -749,13 +757,13 @@ SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
val->literal = strndup(pLiteral->z + 1, pLiteral->n - 2);
|
||||
val->literal = taosStrndup(pLiteral->z + 1, pLiteral->n - 2);
|
||||
} else {
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
val->literal = taosStrndup(pLiteral->z, pLiteral->n);
|
||||
}
|
||||
if (!val->literal) {
|
||||
nodesDestroyNode((SNode*)val);
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pCxt->errCode = terrno;
|
||||
return NULL;
|
||||
}
|
||||
val->flag |= VALUE_FLAG_IS_DURATION;
|
||||
|
@ -801,13 +809,13 @@ SNode* createTimeOffsetValueNode(SAstCreateContext* pCxt, const SToken* pLiteral
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
val->literal = strndup(pLiteral->z + 1, pLiteral->n - 2);
|
||||
val->literal = taosStrndup(pLiteral->z + 1, pLiteral->n - 2);
|
||||
} else {
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
val->literal = taosStrndup(pLiteral->z, pLiteral->n);
|
||||
}
|
||||
if (!val->literal) {
|
||||
nodesDestroyNode((SNode*)val);
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pCxt->errCode = terrno;
|
||||
return NULL;
|
||||
}
|
||||
val->flag |= VALUE_FLAG_IS_TIME_OFFSET;
|
||||
|
@ -853,9 +861,9 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera
|
|||
SValueNode* val = NULL;
|
||||
pCxt->errCode = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&val);
|
||||
CHECK_MAKE_NODE(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
val->literal = taosStrndup(pLiteral->z, pLiteral->n);
|
||||
if (!val->literal) {
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pCxt->errCode = terrno;
|
||||
nodesDestroyNode((SNode*)val);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1079,9 +1079,9 @@ static int32_t parseTableOptions(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
|||
return buildSyntaxErrMsg(&pCxt->msg, "comment too long", token.z);
|
||||
}
|
||||
int32_t len = trimString(token.z, token.n, pCxt->tmpTokenBuf, TSDB_TB_COMMENT_LEN);
|
||||
pStmt->pCreateTblReq->comment = strndup(pCxt->tmpTokenBuf, len);
|
||||
pStmt->pCreateTblReq->comment = taosStrndup(pCxt->tmpTokenBuf, len);
|
||||
if (NULL == pStmt->pCreateTblReq->comment) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
pStmt->pCreateTblReq->commentLen = len;
|
||||
} else {
|
||||
|
|
|
@ -8725,10 +8725,10 @@ static int32_t makeIntervalVal(SRetention* pRetension, int8_t precision, SNode**
|
|||
}
|
||||
char buf[20] = {0};
|
||||
int32_t len = snprintf(buf, sizeof(buf), "%" PRId64 "%c", timeVal, pRetension->freqUnit);
|
||||
pVal->literal = strndup(buf, len);
|
||||
pVal->literal = taosStrndup(buf, len);
|
||||
if (NULL == pVal->literal) {
|
||||
nodesDestroyNode((SNode*)pVal);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
pVal->flag |= VALUE_FLAG_IS_DURATION;
|
||||
pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
|
||||
|
|
|
@ -4352,16 +4352,16 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
|
|||
int32_t numOfBins = 0;
|
||||
int32_t totalCount = 0;
|
||||
|
||||
char *binTypeStr = strndup(varDataVal(pInput[1].columnData->pData), varDataLen(pInput[1].columnData->pData));
|
||||
char *binTypeStr = taosStrndup(varDataVal(pInput[1].columnData->pData), varDataLen(pInput[1].columnData->pData));
|
||||
if (NULL == binTypeStr) {
|
||||
SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
SCL_ERR_RET(terrno);
|
||||
}
|
||||
int8_t binType = getHistogramBinType(binTypeStr);
|
||||
taosMemoryFree(binTypeStr);
|
||||
|
||||
char *binDesc = strndup(varDataVal(pInput[2].columnData->pData), varDataLen(pInput[2].columnData->pData));
|
||||
char *binDesc = taosStrndup(varDataVal(pInput[2].columnData->pData), varDataLen(pInput[2].columnData->pData));
|
||||
if (NULL == binDesc) {
|
||||
SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
SCL_ERR_RET(terrno);
|
||||
}
|
||||
int64_t normalized = *(int64_t *)(pInput[3].columnData->pData);
|
||||
|
||||
|
|
|
@ -313,8 +313,8 @@ int32_t walSkipFetchBody(SWalReader *pRead) {
|
|||
if (pRead->pWal->cfg.encryptAlgorithm == 1) {
|
||||
cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen);
|
||||
}
|
||||
int64_t code = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR);
|
||||
if (code < 0) {
|
||||
int64_t ret = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR);
|
||||
if (ret < 0) {
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,20 +109,20 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
|||
char fnameStr[WAL_FILE_LEN];
|
||||
if (pWal->pLogFile != NULL) {
|
||||
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) {
|
||||
TAOS_RETURN(terrno);
|
||||
return -1;
|
||||
}
|
||||
code = taosCloseFile(&pWal->pLogFile);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(terrno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (pWal->pIdxFile != NULL) {
|
||||
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) {
|
||||
TAOS_RETURN(terrno);
|
||||
return -1;
|
||||
}
|
||||
code = taosCloseFile(&pWal->pIdxFile);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(terrno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
|||
if (pIdxTFile == NULL) {
|
||||
pWal->pIdxFile = NULL;
|
||||
|
||||
TAOS_RETURN(terrno);
|
||||
return -1;
|
||||
}
|
||||
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
|
@ -147,7 +147,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
|||
TAOS_UNUSED(taosCloseFile(&pIdxTFile));
|
||||
pWal->pLogFile = NULL;
|
||||
|
||||
TAOS_RETURN(terrno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWal->pLogFile = pLogTFile;
|
||||
|
@ -160,7 +160,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
|||
int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||
TAOS_UNUSED(taosThreadRwlockWrlock(&pWal->mutex));
|
||||
wInfo("vgId:%d, wal rollback for version %" PRId64, pWal->cfg.vgId, ver);
|
||||
int64_t code;
|
||||
int64_t ret;
|
||||
char fnameStr[WAL_FILE_LEN];
|
||||
if (ver > pWal->vers.lastVer || ver <= pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) {
|
||||
TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex));
|
||||
|
@ -171,11 +171,11 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
// find correct file
|
||||
if (ver < walGetLastFileFirstVer(pWal)) {
|
||||
// change current files
|
||||
code = walChangeWrite(pWal, ver);
|
||||
if (code < 0) {
|
||||
ret = walChangeWrite(pWal, ver);
|
||||
if (ret < 0) {
|
||||
TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex));
|
||||
|
||||
TAOS_RETURN(code);
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
|
||||
// delete files in descending order
|
||||
|
@ -205,8 +205,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
TAOS_RETURN(terrno);
|
||||
}
|
||||
int64_t idxOff = walGetVerIdxOffset(pWal, ver);
|
||||
code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET);
|
||||
if (code < 0) {
|
||||
ret = taosLSeekFile(pIdxFile, idxOff, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex));
|
||||
|
||||
TAOS_RETURN(terrno);
|
||||
|
@ -229,8 +229,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET);
|
||||
if (code < 0) {
|
||||
ret = taosLSeekFile(pLogFile, entry.offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
// TODO
|
||||
TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex));
|
||||
|
||||
|
@ -244,7 +244,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
|
||||
TAOS_RETURN(terrno);
|
||||
}
|
||||
code = walValidHeadCksum(&head);
|
||||
int32_t code = walValidHeadCksum(&head);
|
||||
|
||||
if (code != 0) {
|
||||
TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex));
|
||||
|
|
|
@ -65,7 +65,7 @@ uint32_t taosSafeRand(void) {
|
|||
if (pFile == NULL) {
|
||||
seed = (int)taosGetTimestampSec();
|
||||
} else {
|
||||
int len = taosReadFile(pFile, &seed, sizeof(seed));
|
||||
int64_t len = taosReadFile(pFile, &seed, sizeof(seed));
|
||||
if (len < 0) {
|
||||
seed = (int)taosGetTimestampSec();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ char *strsep(char **stringp, const char *delim) {
|
|||
/* NOTREACHED */
|
||||
}
|
||||
/* Duplicate a string, up to at most size characters */
|
||||
char *strndup(const char *s, int size) {
|
||||
char *taosStrndup(const char *s, int size) {
|
||||
if (s == NULL) return NULL;
|
||||
size_t l;
|
||||
char *s2;
|
||||
l = strlen(s);
|
||||
|
@ -72,6 +73,8 @@ char *strndup(const char *s, int size) {
|
|||
if (s2) {
|
||||
strncpy(s2, s, l);
|
||||
s2[l] = '\0';
|
||||
} else {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return s2;
|
||||
}
|
||||
|
@ -84,6 +87,17 @@ char *stpncpy(char *dest, const char *src, int n) {
|
|||
if (size == n) return dest;
|
||||
return memset(dest, '\0', n - size);
|
||||
}
|
||||
#else
|
||||
char *taosStrndup(const char *s, int size) {
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
char *p = strndup(s, size);
|
||||
if (NULL == p) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t taosStr2int64(const char *str, int64_t *val) {
|
||||
|
|
|
@ -1057,7 +1057,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
|
|||
int n = snprintf(uid, uidlen, "%.*s", (int)sizeof(buf), buf); // though less performance, much safer
|
||||
return 0;
|
||||
#else
|
||||
int len = 0;
|
||||
int64_t len = 0;
|
||||
|
||||
// fd = open("/proc/sys/kernel/random/uuid", 0);
|
||||
TdFilePtr pFile = taosOpenFile("/proc/sys/kernel/random/uuid", TD_FILE_READ);
|
||||
|
@ -1067,7 +1067,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
|
|||
len = taosReadFile(pFile, uid, uidlen);
|
||||
TAOS_SKIP_ERROR(taosCloseFile(&pFile));
|
||||
if (len < 0) {
|
||||
return len;
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ TEST(osStringTests, strsepNullInput) {
|
|||
TEST(osStringTests, strndupNormalInput) {
|
||||
const char s[] = "This is a test string.";
|
||||
int size = strlen(s) + 1;
|
||||
char * s2 = strndup(s, size);
|
||||
char * s2 = taosStrndup(s, size);
|
||||
|
||||
EXPECT_STREQ(s, s2);
|
||||
|
||||
|
|
|
@ -134,9 +134,8 @@ static uint64_t allocateNewPositionInFile(SDiskbasedBuf* pBuf, size_t size) {
|
|||
static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize + POINTER_BYTES + sizeof(SFilePage); }
|
||||
|
||||
static int32_t doFlushBufPageImpl(SDiskbasedBuf* pBuf, int64_t offset, const char* pData, int32_t size) {
|
||||
int32_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET);
|
||||
if (ret == -1) {
|
||||
terrno = terrno;
|
||||
int64_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
|
@ -246,14 +245,14 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
|||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET);
|
||||
if (ret == -1) {
|
||||
int64_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
ret = terrno;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* pPage = (void*)GET_PAYLOAD_DATA(pg);
|
||||
ret = (int32_t)taosReadFile(pBuf->pFile, pPage, pg->length);
|
||||
ret = taosReadFile(pBuf->pFile, pPage, pg->length);
|
||||
if (ret != pg->length) {
|
||||
ret = terrno;
|
||||
return ret;
|
||||
|
|
|
@ -1528,7 +1528,7 @@ bool needInsertFrom(char* sql, int len) {
|
|||
|
||||
// p is string following select keyword
|
||||
bool appendAfterSelect(TAOS* con, SShellCmd* cmd, char* sql, int32_t len) {
|
||||
char* p = strndup(sql, len);
|
||||
char* p = taosStrndup(sql, len);
|
||||
|
||||
// union all
|
||||
char* p1;
|
||||
|
@ -1637,7 +1637,7 @@ bool matchSelectQuery(TAOS* con, SShellCmd* cmd) {
|
|||
}
|
||||
|
||||
// search
|
||||
char* sql_cp = strndup(p, len);
|
||||
char* sql_cp = taosStrndup(p, len);
|
||||
int32_t n = searchAfterSelect(sql_cp, len);
|
||||
taosMemoryFree(sql_cp);
|
||||
if (n == -1 || n > len) return false;
|
||||
|
@ -1712,7 +1712,7 @@ bool matchCreateTable(TAOS* con, SShellCmd* cmd) {
|
|||
p += 13;
|
||||
len -= 13;
|
||||
|
||||
char* ps = strndup(p, len);
|
||||
char* ps = taosStrndup(p, len);
|
||||
bool ret = false;
|
||||
char* last = lastWord(ps);
|
||||
|
||||
|
@ -1765,7 +1765,7 @@ bool matchOther(TAOS* con, SShellCmd* cmd) {
|
|||
if (len < 8) return false;
|
||||
|
||||
// like 'from ( '
|
||||
char* sql = strndup(p, len);
|
||||
char* sql = taosStrndup(p, len);
|
||||
char* last = lastWord(sql);
|
||||
|
||||
if (strcmp(last, "from(") == 0) {
|
||||
|
@ -1828,7 +1828,7 @@ bool matchOther(TAOS* con, SShellCmd* cmd) {
|
|||
bool matchEnd(TAOS* con, SShellCmd* cmd) {
|
||||
// str dump
|
||||
bool ret = false;
|
||||
char* ps = strndup(cmd->command, cmd->commandSize);
|
||||
char* ps = taosStrndup(cmd->command, cmd->commandSize);
|
||||
char* last = lastWord(ps);
|
||||
char* elast = strrchr(last, '.'); // find end last
|
||||
if (elast) {
|
||||
|
|
Loading…
Reference in New Issue