Coverage Report

Created: 2026-10-22 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tdengine/include/util/tRealloc.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * SPDX-License-Identifier: AGPL-3.0-or-later
5
 *
6
 * This program is free software: you can use, redistribute, and/or modify
7
 * it under the terms of the GNU Affero General Public License, version 3
8
 * or later ("AGPL"), as published by the Free Software Foundation.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#ifndef _TD_UTIL_TREALLOC_H_
19
#define _TD_UTIL_TREALLOC_H_
20
21
#include "os.h"
22
23
#ifdef __cplusplus
24
extern "C" {
25
#endif
26
27
0
static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) {
28
0
  int32_t  code = 0;
29
0
  int64_t  bsize = 0;
30
0
  uint8_t *pBuf = NULL;
31
32
0
  if (*ppBuf) {
33
0
    pBuf = (*ppBuf) - sizeof(int64_t);
34
0
    bsize = *(int64_t *)pBuf;
35
0
  }
36
37
0
  if (bsize >= size) goto _exit;
38
39
0
  if (bsize == 0) bsize = 64;
40
0
  while (bsize < size) {
41
0
    bsize *= 2;
42
0
  }
43
44
0
  pBuf = (uint8_t *)taosMemoryRealloc(pBuf, bsize + sizeof(int64_t));
45
0
  if (pBuf == NULL) {
46
0
    code = terrno;
47
0
    goto _exit;
48
0
  }
49
50
0
  *(int64_t *)pBuf = bsize;
51
0
  *ppBuf = pBuf + sizeof(int64_t);
52
53
0
_exit:
54
0
  return code;
55
0
}
Unexecuted instantiation: parInsertUtil.c:tRealloc
Unexecuted instantiation: tdataformat.c:tRealloc
Unexecuted instantiation: tmsg.c:tRealloc
56
57
#define tFree(BUF)                                        \
58
0
  do {                                                    \
59
0
    if (BUF) {                                            \
60
0
      taosMemoryFree((uint8_t *)(BUF) - sizeof(int64_t)); \
61
0
      (BUF) = NULL;                                       \
62
0
    }                                                     \
63
0
  } while (0)
64
65
#ifdef __cplusplus
66
}
67
#endif
68
69
#endif /*_TD_UTIL_TREALLOC_H_*/