• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3535

23 Nov 2024 02:07AM UTC coverage: 60.85% (+0.03%) from 60.825%
#3535

push

travis-ci

web-flow
Merge pull request #28893 from taosdata/doc/internal

refact: rename taos lib name

120252 of 252737 branches covered (47.58%)

Branch coverage included in aggregate %.

201187 of 275508 relevant lines covered (73.02%)

15886166.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.42
/include/util/tRealloc.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef _TD_UTIL_TREALLOC_H_
17
#define _TD_UTIL_TREALLOC_H_
18

19
#include "os.h"
20

21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24

25
static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) {
26
  int32_t  code = 0;
2,147,483,647✔
27
  int64_t  bsize = 0;
2,147,483,647✔
28
  uint8_t *pBuf = NULL;
2,147,483,647✔
29

30
  if (*ppBuf) {
2,147,483,647!
31
    pBuf = (*ppBuf) - sizeof(int64_t);
2,147,483,647✔
32
    bsize = *(int64_t *)pBuf;
2,147,483,647✔
33
  }
34

35
  if (bsize >= size) goto _exit;
2,147,483,647!
36

37
  if (bsize == 0) bsize = 64;
516,530,082!
38
  while (bsize < size) {
844,396,325!
39
    bsize *= 2;
327,866,243✔
40
  }
41

42
  pBuf = (uint8_t *)taosMemoryRealloc(pBuf, bsize + sizeof(int64_t));
516,530,082✔
43
  if (pBuf == NULL) {
525,167,941!
44
    code = terrno;
×
45
    goto _exit;
×
46
  }
47

48
  *(int64_t *)pBuf = bsize;
525,226,150✔
49
  *ppBuf = pBuf + sizeof(int64_t);
525,226,150✔
50

51
_exit:
2,147,483,647✔
52
  return code;
2,147,483,647✔
53
}
54

55
#define tFree(BUF)                                        \
56
  do {                                                    \
57
    if (BUF) {                                            \
58
      taosMemoryFree((uint8_t *)(BUF) - sizeof(int64_t)); \
59
      (BUF) = NULL;                                       \
60
    }                                                     \
61
  } while (0)
62

63
#ifdef __cplusplus
64
}
65
#endif
66

67
#endif /*_TD_UTIL_TREALLOC_H_*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc