Merge pull request #29133 from taosdata/enh/TD-32403-3.0
enh: [TD-32403] replace unsafe functions
This commit is contained in:
commit
90272cf0c7
|
@ -21,19 +21,19 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SCryptOpts{
|
||||
int32_t len;
|
||||
char* source;
|
||||
char* result;
|
||||
int32_t unitLen;
|
||||
unsigned char key[17];
|
||||
}SCryptOpts;
|
||||
typedef struct SCryptOpts {
|
||||
int32_t len;
|
||||
char* source;
|
||||
char* result;
|
||||
int32_t unitLen;
|
||||
char key[17];
|
||||
} SCryptOpts;
|
||||
|
||||
int32_t CBC_Decrypt(SCryptOpts *opts);
|
||||
int32_t CBC_Encrypt(SCryptOpts *opts);
|
||||
int32_t CBC_Decrypt(SCryptOpts* opts);
|
||||
int32_t CBC_Encrypt(SCryptOpts* opts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _CRYPT_H_
|
||||
#endif // _CRYPT_H_
|
|
@ -10381,7 +10381,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
|||
char name[TSDB_COL_NAME_LEN] = {0};
|
||||
char *tmp = NULL;
|
||||
TAOS_CHECK_EXIT(tDecodeCStr(pCoder, &tmp));
|
||||
strncpy(name, tmp, TSDB_COL_NAME_LEN - 1);
|
||||
tstrncpy(name, tmp, TSDB_COL_NAME_LEN);
|
||||
if (taosArrayPush(pReq->ctb.tagName, name) == NULL) {
|
||||
TAOS_CHECK_EXIT(terrno);
|
||||
}
|
||||
|
@ -12417,7 +12417,7 @@ void setFieldWithOptions(SFieldWithOptions *fieldWithOptions, SField *field) {
|
|||
fieldWithOptions->bytes = field->bytes;
|
||||
fieldWithOptions->flags = field->flags;
|
||||
fieldWithOptions->type = field->type;
|
||||
strncpy(fieldWithOptions->name, field->name, TSDB_COL_NAME_LEN);
|
||||
tstrncpy(fieldWithOptions->name, field->name, TSDB_COL_NAME_LEN);
|
||||
}
|
||||
int32_t tSerializeTableTSMAInfoReq(void *buf, int32_t bufLen, const STableTSMAInfoReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
|
|
|
@ -1434,7 +1434,7 @@ static void debugPrintTagVal(int8_t type, const void *val, int32_t vlen, const c
|
|||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_GEOMETRY: {
|
||||
char tmpVal[32] = {0};
|
||||
strncpy(tmpVal, val, vlen > 31 ? 31 : vlen);
|
||||
tstrncpy(tmpVal, val, vlen > 31 ? 31 : vlen);
|
||||
printf("%s:%d type:%d vlen:%d, val:\"%s\"\n", tag, ln, (int32_t)type, vlen, tmpVal);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
|
|
|
@ -622,7 +622,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
char defaultFqdn[TSDB_FQDN_LEN] = {0};
|
||||
int32_t defaultServerPort = 6030;
|
||||
if (taosGetFqdn(defaultFqdn) != 0) {
|
||||
(void)strcpy(defaultFqdn, "localhost");
|
||||
tstrncpy(defaultFqdn, "localhost", TSDB_FQDN_LEN);
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(
|
||||
|
|
|
@ -81,7 +81,7 @@ SName* tNameDup(const SName* name) {
|
|||
}
|
||||
|
||||
int32_t tNameGetDbName(const SName* name, char* dst) {
|
||||
strncpy(dst, name->dbname, tListLen(name->dbname));
|
||||
tstrncpy(dst, name->dbname, tListLen(name->dbname));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
|||
#if defined(TD_ENTERPRISE)
|
||||
pCfg->tdbEncryptAlgorithm = pCreate->encryptAlgorithm;
|
||||
if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) {
|
||||
strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
}
|
||||
#else
|
||||
pCfg->tdbEncryptAlgorithm = 0;
|
||||
|
|
|
@ -551,7 +551,7 @@ int32_t dmGetEncryptKey() {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
strncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN + 1);
|
||||
tstrncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN + 1);
|
||||
taosMemoryFreeClear(encryptKey);
|
||||
tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, strlen(tsEncryptKey));
|
||||
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
|
||||
|
|
|
@ -197,7 +197,7 @@ static int32_t metaOpenImpl(SVnode *pVnode, SMeta **ppMeta, const char *metaDir,
|
|||
code = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx, 0);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
sprintf(indexFullPath, "%s/%s", pMeta->path, "invert");
|
||||
(void)tsnprintf(indexFullPath, sizeof(indexFullPath), "%s/%s", pMeta->path, "invert");
|
||||
ret = taosMkDir(indexFullPath);
|
||||
|
||||
SIndexOpts opts = {.cacheSize = 8 * 1024 * 1024};
|
||||
|
@ -209,7 +209,7 @@ static int32_t metaOpenImpl(SVnode *pVnode, SMeta **ppMeta, const char *metaDir,
|
|||
|
||||
// open pTtlMgr ("ttlv1.idx")
|
||||
char logPrefix[128] = {0};
|
||||
sprintf(logPrefix, "vgId:%d", TD_VID(pVnode));
|
||||
(void)tsnprintf(logPrefix, sizeof(logPrefix), "vgId:%d", TD_VID(pVnode));
|
||||
code = ttlMgrOpen(&pMeta->pTtlMgr, pMeta->pEnv, 0, logPrefix, tsTtlFlushThreshold);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName) {
|
|||
metaReaderClear(&mr);
|
||||
return code;
|
||||
}
|
||||
strncpy(tbName, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
tstrncpy(tbName, mr.me.name, TSDB_TABLE_NAME_LEN);
|
||||
metaReaderClear(&mr);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -104,7 +104,7 @@ int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppF
|
|||
}
|
||||
|
||||
pFD->path = (char *)&pFD[1];
|
||||
strcpy(pFD->path, path);
|
||||
tstrncpy(pFD->path, path, strlen(path) + 1);
|
||||
pFD->szPage = szPage;
|
||||
pFD->flag = flag;
|
||||
pFD->szPage = szPage;
|
||||
|
@ -174,7 +174,6 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
|
|||
opts.source = pFD->pBuf + count;
|
||||
opts.result = PacketData;
|
||||
opts.unitLen = 128;
|
||||
// strncpy(opts.key, tsEncryptKey, 16);
|
||||
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
|
||||
|
||||
NewLen = CBC_Encrypt(&opts);
|
||||
|
@ -248,7 +247,6 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor
|
|||
opts.source = pFD->pBuf + count;
|
||||
opts.result = PacketData;
|
||||
opts.unitLen = 128;
|
||||
// strncpy(opts.key, tsEncryptKey, 16);
|
||||
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
|
||||
|
||||
NewLen = CBC_Decrypt(&opts);
|
||||
|
|
|
@ -330,7 +330,7 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
strcpy((char *)((*async) + 1), label);
|
||||
tstrncpy((char *)((*async) + 1), label, strlen(label) + 1);
|
||||
(*async)->label = (const char *)((*async) + 1);
|
||||
|
||||
(void)taosThreadMutexInit(&(*async)->mutex, NULL);
|
||||
|
|
|
@ -303,7 +303,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
|||
if (tsEncryptKey[0] == 0) {
|
||||
return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
} else {
|
||||
strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -168,7 +168,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t
|
|||
|
||||
static int32_t vnodeVgroupIdLen(int32_t vgId) {
|
||||
char tmp[TSDB_FILENAME_LEN];
|
||||
sprintf(tmp, "%d", vgId);
|
||||
(void)tsnprintf(tmp, TSDB_FILENAME_LEN, "%d", vgId);
|
||||
return strlen(tmp);
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr
|
|||
char *tsdbFilePrefixPos = strstr(oldRname, tsdbFilePrefix);
|
||||
if (tsdbFilePrefixPos == NULL) continue;
|
||||
|
||||
int32_t tsdbFileVgId = 0; // atoi(tsdbFilePrefixPos + prefixLen);
|
||||
int32_t tsdbFileVgId = 0;
|
||||
ret = taosStr2int32(tsdbFilePrefixPos + prefixLen, &tsdbFileVgId);
|
||||
if (ret != 0) {
|
||||
vError("vgId:%d, failed to get tsdb file vgid since %s", dstVgId, tstrerror(ret));
|
||||
|
@ -417,7 +417,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
|
|||
}
|
||||
|
||||
pVnode->path = (char *)&pVnode[1];
|
||||
strcpy(pVnode->path, path);
|
||||
tstrncpy(pVnode->path, path, strlen(path) + 1);
|
||||
pVnode->config = info.config;
|
||||
pVnode->state.committed = info.state.committed;
|
||||
pVnode->state.commitTerm = info.state.commitTerm;
|
||||
|
@ -472,7 +472,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
|
|||
}
|
||||
|
||||
// open wal
|
||||
sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR);
|
||||
(void)tsnprintf(tdir, sizeof(tdir), "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR);
|
||||
ret = taosRealPath(tdir, NULL, sizeof(tdir));
|
||||
TAOS_UNUSED(ret);
|
||||
|
||||
|
@ -484,7 +484,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
|
|||
}
|
||||
|
||||
// open tq
|
||||
sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_TQ_DIR);
|
||||
(void)tsnprintf(tdir, sizeof(tdir), "%s%s%s", dir, TD_DIRSEP, VNODE_TQ_DIR);
|
||||
ret = taosRealPath(tdir, NULL, sizeof(tdir));
|
||||
TAOS_UNUSED(ret);
|
||||
|
||||
|
|
|
@ -71,11 +71,11 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
|
||||
if (infoReq.option == REQ_OPT_TBUID) reqTbUid = true;
|
||||
metaRsp.dbId = pVnode->config.dbId;
|
||||
(void)strcpy(metaRsp.tbName, infoReq.tbName);
|
||||
tstrncpy(metaRsp.tbName, infoReq.tbName, TSDB_TABLE_NAME_LEN);
|
||||
(void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
|
||||
|
||||
if (!reqTbUid) {
|
||||
TAOS_UNUSED(sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName));
|
||||
(void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", infoReq.dbFName, infoReq.tbName);
|
||||
code = vnodeValidateTableHash(pVnode, tableFName);
|
||||
if (code) {
|
||||
goto _exit4;
|
||||
|
@ -105,7 +105,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
metaRsp.tuid = mer1.me.uid;
|
||||
|
||||
if (mer1.me.type == TSDB_SUPER_TABLE) {
|
||||
(void)strcpy(metaRsp.stbName, mer1.me.name);
|
||||
tstrncpy(metaRsp.stbName, mer1.me.name, TSDB_TABLE_NAME_LEN);
|
||||
schema = mer1.me.stbEntry.schemaRow;
|
||||
schemaTag = mer1.me.stbEntry.schemaTag;
|
||||
metaRsp.suid = mer1.me.uid;
|
||||
|
@ -113,7 +113,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_NOLOCK);
|
||||
if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit2;
|
||||
|
||||
(void)strcpy(metaRsp.stbName, mer2.me.name);
|
||||
tstrncpy(metaRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
|
||||
metaRsp.suid = mer2.me.uid;
|
||||
schema = mer2.me.stbEntry.schemaRow;
|
||||
schemaTag = mer2.me.stbEntry.schemaTag;
|
||||
|
@ -220,10 +220,10 @@ int32_t vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
(void)strcpy(cfgRsp.tbName, cfgReq.tbName);
|
||||
tstrncpy(cfgRsp.tbName, cfgReq.tbName, TSDB_TABLE_NAME_LEN);
|
||||
(void)memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));
|
||||
|
||||
(void)sprintf(tableFName, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
|
||||
(void)tsnprintf(tableFName, TSDB_TABLE_FNAME_LEN, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
|
||||
code = vnodeValidateTableHash(pVnode, tableFName);
|
||||
if (code) {
|
||||
goto _exit;
|
||||
|
@ -246,7 +246,7 @@ int32_t vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
metaReaderDoInit(&mer2, pVnode->pMeta, META_READER_LOCK);
|
||||
if (metaReaderGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
|
||||
|
||||
(void)strcpy(cfgRsp.stbName, mer2.me.name);
|
||||
tstrncpy(cfgRsp.stbName, mer2.me.name, TSDB_TABLE_NAME_LEN);
|
||||
schema = mer2.me.stbEntry.schemaRow;
|
||||
schemaTag = mer2.me.stbEntry.schemaTag;
|
||||
cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
|
||||
|
|
|
@ -968,7 +968,7 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
|
|||
return;
|
||||
}
|
||||
|
||||
strcpy(pMetaRsp->dbFName, pVnode->config.dbname);
|
||||
tstrncpy(pMetaRsp->dbFName, pVnode->config.dbname, TSDB_DB_FNAME_LEN);
|
||||
pMetaRsp->dbId = pVnode->config.dbId;
|
||||
pMetaRsp->vgId = TD_VID(pVnode);
|
||||
pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
|
||||
|
@ -1216,7 +1216,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
strcpy(str, pCreateReq->name);
|
||||
tstrncpy(str, pCreateReq->name, TSDB_TABLE_FNAME_LEN);
|
||||
if (taosArrayPush(tbNames, &str) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rcode = -1;
|
||||
|
@ -1225,7 +1225,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
}
|
||||
|
||||
// validate hash
|
||||
sprintf(tbName, "%s.%s", pVnode->config.dbname, pCreateReq->name);
|
||||
(void)tsnprintf(tbName, TSDB_TABLE_FNAME_LEN, "%s.%s", pVnode->config.dbname, pCreateReq->name);
|
||||
if (vnodeValidateTableHash(pVnode, tbName) < 0) {
|
||||
cRsp.code = TSDB_CODE_VND_HASH_MISMATCH;
|
||||
if (taosArrayPush(rsp.pArray, &cRsp) == NULL) {
|
||||
|
@ -1518,7 +1518,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in
|
|||
pRsp->code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
strcpy(str, pDropTbReq->name);
|
||||
tstrncpy(str, pDropTbReq->name, TSDB_TABLE_FNAME_LEN);
|
||||
if (taosArrayPush(tbNames, &str) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pRsp->code = terrno;
|
||||
|
|
|
@ -99,8 +99,8 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData
|
|||
return terrno;
|
||||
}
|
||||
|
||||
(void)sprintf(
|
||||
wktPatternWithSpace,
|
||||
(void)tsnprintf(
|
||||
wktPatternWithSpace, 4 * 1024,
|
||||
"^( *)point( *)z?m?( *)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( "
|
||||
"*)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?){1,3}( *)\\)))|linestring( *)z?m?( "
|
||||
"*)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( "
|
||||
|
|
|
@ -692,7 +692,7 @@ int32_t syncGetArbToken(int64_t rid, char* outToken) {
|
|||
|
||||
memset(outToken, 0, TSDB_ARB_TOKEN_SIZE);
|
||||
(void)taosThreadMutexLock(&pSyncNode->arbTokenMutex);
|
||||
strncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE);
|
||||
tstrncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE);
|
||||
(void)taosThreadMutexUnlock(&pSyncNode->arbTokenMutex);
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
|
|
@ -262,7 +262,7 @@ int tdbPagerBegin(SPager *pPager, TXN *pTxn) {
|
|||
*/
|
||||
// Open the journal
|
||||
char jTxnFileName[TDB_FILENAME_LEN];
|
||||
sprintf(jTxnFileName, "%s.%" PRId64, pPager->jFileName, pTxn->txnId);
|
||||
(void)tsnprintf(jTxnFileName, TDB_FILENAME_LEN, "%s.%" PRId64, pPager->jFileName, pTxn->txnId);
|
||||
pTxn->jfd = tdbOsOpen(jTxnFileName, TDB_O_CREAT | TDB_O_RDWR, 0755);
|
||||
if (TDB_FD_INVALID(pTxn->jfd)) {
|
||||
tdbError("failed to open file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
|
||||
|
@ -365,7 +365,7 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
|
|||
|
||||
int tdbPagerPostCommit(SPager *pPager, TXN *pTxn) {
|
||||
char jTxnFileName[TDB_FILENAME_LEN];
|
||||
sprintf(jTxnFileName, "%s.%" PRId64, pPager->jFileName, pTxn->txnId);
|
||||
(void)tsnprintf(jTxnFileName, TDB_FILENAME_LEN, "%s.%" PRId64, pPager->jFileName, pTxn->txnId);
|
||||
|
||||
// remove the journal file
|
||||
if (tdbOsClose(pTxn->jfd) < 0) {
|
||||
|
@ -595,7 +595,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
|
|||
}
|
||||
|
||||
char jTxnFileName[TDB_FILENAME_LEN];
|
||||
sprintf(jTxnFileName, "%s.%" PRId64, pPager->jFileName, pTxn->txnId);
|
||||
(void)tsnprintf(jTxnFileName, TDB_FILENAME_LEN, "%s.%" PRId64, pPager->jFileName, pTxn->txnId);
|
||||
|
||||
if (tdbOsRemove(jTxnFileName) < 0 && errno != ENOENT) {
|
||||
tdbError("failed to remove file due to %s. file:%s", strerror(errno), jTxnFileName);
|
||||
|
@ -1179,7 +1179,7 @@ int tdbPagerRestoreJournals(SPager *pPager) {
|
|||
int dirLen = strlen(pPager->pEnv->dbName);
|
||||
memcpy(jname, pPager->pEnv->dbName, dirLen);
|
||||
jname[dirLen] = '/';
|
||||
sprintf(jname + dirLen + 1, TDB_MAINDB_NAME "-journal.%" PRId64, *pTxnId);
|
||||
(void)tsnprintf(jname + dirLen + 1, TD_PATH_MAX - dirLen - 1, TDB_MAINDB_NAME "-journal.%" PRId64, *pTxnId);
|
||||
code = tdbPagerRestore(pPager, jname);
|
||||
if (code) {
|
||||
taosArrayDestroy(pTxnList);
|
||||
|
|
|
@ -539,7 +539,7 @@ int32_t decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const
|
|||
opts.source = pHead->head.body;
|
||||
opts.result = newBody;
|
||||
opts.unitLen = 16;
|
||||
TAOS_UNUSED(strncpy((char *)opts.key, cfg->encryptKey, 16));
|
||||
tstrncpy((char *)opts.key, cfg->encryptKey, sizeof(opts.key));
|
||||
|
||||
int32_t count = CBC_Decrypt(&opts);
|
||||
|
||||
|
|
|
@ -1395,14 +1395,14 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
int32_t len = 0;
|
||||
char newValue[1024] = {0};
|
||||
|
||||
strcpy(newValue, value);
|
||||
tstrncpy(newValue, value, sizeof(newValue));
|
||||
|
||||
int32_t count = 1;
|
||||
while (vlen < 1024) {
|
||||
(void)paGetToken(value + vlen + 1 * count, &tmp, &len);
|
||||
if (len == 0) break;
|
||||
tmp[len] = 0;
|
||||
strcpy(newValue + vlen, tmp);
|
||||
tstrncpy(newValue + vlen, tmp, sizeof(newValue) - vlen);
|
||||
vlen += len;
|
||||
count++;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,6 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c
|
|||
char *p = cfgNameStr;
|
||||
if (envNameStr[0] != 'T' || envNameStr[1] != 'A' || envNameStr[2] != 'O' || envNameStr[3] != 'S' ||
|
||||
envNameStr[4] != '_') {
|
||||
// if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1);
|
||||
// p[cfgNameMaxLen - 1] = '\0';
|
||||
// return strlen(cfgNameStr);
|
||||
cfgNameStr[0] = '\0';
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
@ -57,7 +54,9 @@ int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
|||
if (envStr == NULL || cfgStr == NULL) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
if (cfgStr != envStr) strcpy(cfgStr, envStr);
|
||||
if (cfgStr != envStr) {
|
||||
tstrncpy(cfgStr, envStr, strlen(envStr) + 1);
|
||||
}
|
||||
char *p = strchr(cfgStr, '=');
|
||||
|
||||
if (p != NULL) {
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tjson.h"
|
||||
#include "tutil.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define LOG_MAX_LINE_SIZE (10024)
|
||||
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
|
||||
|
@ -166,9 +166,9 @@ static int32_t taosStartLog() {
|
|||
}
|
||||
|
||||
static int32_t getDay(char *buf, int32_t bufSize) {
|
||||
time_t t;
|
||||
time_t t;
|
||||
int32_t code = taosTime(&t);
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
struct tm tmInfo;
|
||||
|
@ -204,8 +204,8 @@ int32_t taosInitSlowLog() {
|
|||
|
||||
getFullPathName(tsLogObj.slowLogName, logFileName);
|
||||
|
||||
char name[PATH_MAX + TD_TIME_STR_LEN] = {0};
|
||||
char day[TD_TIME_STR_LEN] = {0};
|
||||
char name[PATH_MAX + TD_TIME_STR_LEN] = {0};
|
||||
char day[TD_TIME_STR_LEN] = {0};
|
||||
int32_t code = getDay(day, sizeof(day));
|
||||
if (code != 0) {
|
||||
(void)printf("failed to get day, reason:%s\n", tstrerror(code));
|
||||
|
@ -299,9 +299,7 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void taosSetNoNewFile() {
|
||||
tsLogObj.openInProgress = 1;
|
||||
}
|
||||
void taosSetNoNewFile() { tsLogObj.openInProgress = 1; }
|
||||
|
||||
static void taosStopLog() {
|
||||
if (tsLogObj.logHandle) {
|
||||
|
@ -503,7 +501,7 @@ static void taosOpenNewSlowLogFile() {
|
|||
taosWriteLog(tsLogObj.slowHandle);
|
||||
atomic_store_32(&tsLogObj.slowHandle->lock, 0);
|
||||
|
||||
char day[TD_TIME_STR_LEN] = {0};
|
||||
char day[TD_TIME_STR_LEN] = {0};
|
||||
int32_t code = getDay(day, sizeof(day));
|
||||
if (code != 0) {
|
||||
uError("failed to get day, reason:%s", tstrerror(code));
|
||||
|
@ -882,32 +880,6 @@ void taosPrintSlowLog(const char *format, ...) {
|
|||
taosMemoryFree(buffer);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void taosDumpData(unsigned char *msg, int32_t len) {
|
||||
if (!osLogSpaceAvailable()) return;
|
||||
taosUpdateLogNums(DEBUG_DUMP);
|
||||
|
||||
char temp[256] = {0};
|
||||
int32_t i, pos = 0, c = 0;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
sprintf(temp + pos, "%02x ", msg[i]);
|
||||
c++;
|
||||
pos += 3;
|
||||
if (c >= 16) {
|
||||
temp[pos++] = '\n';
|
||||
TAOS_UNUSED((taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos) <= 0));
|
||||
c = 0;
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
temp[pos++] = '\n';
|
||||
|
||||
TAOS_UNUSED(taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos));
|
||||
}
|
||||
#endif
|
||||
|
||||
static void taosCloseLogByFd(TdFilePtr pFile) {
|
||||
if (pFile != NULL) {
|
||||
taosUnLockLogFile(pFile);
|
||||
|
|
|
@ -95,33 +95,14 @@ static int32_t parseCfgIntWithUnit(const char* str, int64_t* res) {
|
|||
}
|
||||
|
||||
int32_t taosStrHumanToInt64(const char* str, int64_t* out) {
|
||||
int64_t res;
|
||||
int64_t res;
|
||||
int32_t code = parseCfgIntWithUnit(str, &res);
|
||||
if (code == TSDB_CODE_SUCCESS) *out = (int64_t)res;
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef BUILD_NO_CALL
|
||||
void taosInt64ToHumanStr(int64_t val, char* outStr) {
|
||||
if (((val >= UNIT_ONE_EXBIBYTE) || (-val >= UNIT_ONE_EXBIBYTE)) && ((val % UNIT_ONE_EXBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdE", (long long)val / UNIT_ONE_EXBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_PEBIBYTE) || (-val >= UNIT_ONE_PEBIBYTE)) && ((val % UNIT_ONE_PEBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdP", (long long)val / UNIT_ONE_PEBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_TEBIBYTE) || (-val >= UNIT_ONE_TEBIBYTE)) && ((val % UNIT_ONE_TEBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdT", (long long)val / UNIT_ONE_TEBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_GIBIBYTE) || (-val >= UNIT_ONE_GIBIBYTE)) && ((val % UNIT_ONE_GIBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdG", (long long)val / UNIT_ONE_GIBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_MEBIBYTE) || (-val >= UNIT_ONE_MEBIBYTE)) && ((val % UNIT_ONE_MEBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdM", (long long)val / UNIT_ONE_MEBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_KIBIBYTE) || (-val >= UNIT_ONE_KIBIBYTE)) && ((val % UNIT_ONE_KIBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdK", (long long)val / UNIT_ONE_KIBIBYTE);
|
||||
} else
|
||||
sprintf(outStr, "%qd", (long long)val);
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t taosStrHumanToInt32(const char* str, int32_t* out) {
|
||||
int64_t res;
|
||||
int64_t res;
|
||||
int32_t code = parseCfgIntWithUnit(str, &res);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
if (res < INT32_MIN || res > INT32_MAX) {
|
||||
|
@ -131,16 +112,3 @@ int32_t taosStrHumanToInt32(const char* str, int32_t* out) {
|
|||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef BUILD_NO_CALL
|
||||
void taosInt32ToHumanStr(int32_t val, char* outStr) {
|
||||
if (((val >= UNIT_ONE_GIBIBYTE) || (-val >= UNIT_ONE_GIBIBYTE)) && ((val % UNIT_ONE_GIBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdG", (long long)val / UNIT_ONE_GIBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_MEBIBYTE) || (-val >= UNIT_ONE_MEBIBYTE)) && ((val % UNIT_ONE_MEBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdM", (long long)val / UNIT_ONE_MEBIBYTE);
|
||||
} else if (((val >= UNIT_ONE_KIBIBYTE) || (-val >= UNIT_ONE_KIBIBYTE)) && ((val % UNIT_ONE_KIBIBYTE) == 0)) {
|
||||
sprintf(outStr, "%qdK", (long long)val / UNIT_ONE_KIBIBYTE);
|
||||
} else
|
||||
sprintf(outStr, "%qd", (long long)val);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue