diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index eebe0b6b4614d2ba0b1420772bdedc1b758065d3..eeb212fe95ba3e0023c60181a4c1cae2cde0f9d3 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -443,6 +443,11 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { for (uint32_t i = 0; i < pHelper->config.maxTables; i++) { SCompIdx *pCompIdx = pHelper->pCompIdx + i; if (pCompIdx->offset > 0) { + int drift = POINTER_DISTANCE(buf, pHelper->pBuffer); + if (tsizeof(pHelper->pBuffer) - drift < 128) { + pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer)*2); + } + buf = POINTER_SHIFT(pHelper->pBuffer, drift); buf = taosEncodeVariant32(buf, i); buf = tsdbEncodeSCompIdx(buf, pCompIdx); } @@ -469,6 +474,7 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) { ASSERT(pFile->info.offset > TSDB_FILE_HEAD_SIZE); if (lseek(fd, pFile->info.offset, SEEK_SET) < 0) return -1; + if ((pHelper->pBuffer = trealloc(pHelper->pBuffer, pFile->info.len)) == NULL) return -1; if (tread(fd, (void *)(pHelper->pBuffer), pFile->info.len) < pFile->info.len) return -1; if (!taosCheckChecksumWhole((uint8_t *)(pHelper->pBuffer), pFile->info.len)) { diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 5dcb6e406f5c8dccd989ec0e2e8e1d2542177020..255680496a4bbe0b4e10efaed7e06676577e340c 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -46,6 +46,7 @@ extern "C" { // Pointer p drift right by b bytes #define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) +#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) #ifndef NDEBUG #define ASSERT(x) assert(x)