提交 61a7751b 编写于 作者: H Haojun Liao

fix(query): fix bug in tIntToHex and add test case.

上级 fab32ae9
......@@ -1988,14 +1988,12 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
pTaskInfo->schemaInfo.dbname = strdup(dbFName);
pTaskInfo->id.queryId = queryId;
pTaskInfo->execModel = model;
pTaskInfo->pTableInfoList = tableListCreate();
pTaskInfo->stopInfo.pStopInfo = taosArrayInit(4, sizeof(SExchangeOpStopInfo));
pTaskInfo->pResultBlockList = taosArrayInit(128, POINTER_BYTES);
// char* p = taosMemoryMalloc(64);
// snprintf(p, 64, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId);
pTaskInfo->id.queryId = queryId;
pTaskInfo->id.str = buildTaskId(taskId, queryId);
return pTaskInfo;
}
......
......@@ -323,8 +323,13 @@ char *strbetween(char *string, char *begin, char *end) {
int32_t tintToHex(uint64_t val, char hex[]) {
const char hexstr[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
int32_t j = 0;
int32_t k = 0;
int32_t j = 0, k = 0;
if (val == 0) {
hex[j++] = hexstr[0];
return j;
}
// ignore the initial 0
while((val & (((uint64_t)0xfL) << ((15 - k) * 4))) == 0) {
k += 1;
}
......
......@@ -294,4 +294,32 @@ TEST(utilTest, tstrncspn) {
const char* reject5 = "911";
v = tstrncspn(p2, strlen(p2), reject5, 0);
ASSERT_EQ(v, 14);
}
TEST(utilTest, intToHextStr) {
char buf[64] = {0};
int64_t v = 0;
tintToHex(0, buf);
ASSERT_STREQ(buf, "0");
v = 100000000;
tintToHex(v, buf);
char destBuf[128];
sprintf(destBuf, "%" PRIx64, v);
ASSERT_STREQ(buf, destBuf);
taosSeedRand(taosGetTimestampSec());
for(int32_t i = 0; i < 100000; ++i) {
memset(buf, 0, tListLen(buf));
memset(destBuf, 0, tListLen(destBuf));
v = taosRand();
tintToHex(v, buf);
sprintf(destBuf, "%" PRIx64, v);
ASSERT_STREQ(buf, destBuf);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册