diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 4b38f12e1ffabcb47ac052be85c99b938b4b386f..ecacdcd13c463ef4ffc689534d13737d69f15e1b 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -386,16 +386,19 @@ static int tfileReadLoadFst(TFileReader* reader) { static int tfileReadLoadTableIds(TFileReader* reader, int32_t offset, SArray* result) { int32_t nid; WriterCtx* ctx = reader->ctx; - int32_t nread = ctx->readFrom(ctx, (char*)&nid, sizeof(nid), offset); + + int32_t nread = ctx->readFrom(ctx, (char*)&nid, sizeof(nid), offset); assert(sizeof(nid) == nread); - char* buf = calloc(1, sizeof(uint64_t) * nid); + int32_t total = sizeof(uint64_t) * nid; + char* buf = calloc(1, total); if (buf == NULL) { return -1; } - nread = ctx->read(ctx, buf, sizeof(uint64_t) * nid); - uint64_t* ids = (uint64_t*)buf; + nread = ctx->read(ctx, buf, total); + assert(total == nread); + for (int32_t i = 0; i < nid; i++) { - taosArrayPush(result, ids + i); + taosArrayPush(result, (uint64_t*)buf + i); } free(buf); return 0;