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

taosdata / TDengine / #3524

08 Nov 2024 04:27AM UTC coverage: 60.898% (+5.0%) from 55.861%
#3524

push

travis-ci

web-flow
Merge pull request #28647 from taosdata/fix/3.0/TD-32519_drop_ctb

fix TD-32519 drop child table with tsma caused crash

118687 of 248552 branches covered (47.75%)

Branch coverage included in aggregate %.

286 of 337 new or added lines in 18 files covered. (84.87%)

9647 existing lines in 190 files now uncovered.

199106 of 273291 relevant lines covered (72.85%)

15236719.35 hits per line

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

92.71
/source/util/src/tencode.c
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
#define _DEFAULT_SOURCE
17
#include "tencode.h"
18

19
#if __STDC_VERSION__ >= 201112LL
20
static_assert(sizeof(float) == sizeof(uint32_t), "sizeof(float) must equal to sizeof(uint32_t)");
21
static_assert(sizeof(double) == sizeof(uint64_t), "sizeof(double) must equal to sizeof(uint64_t)");
22
#endif
23

24
struct SEncoderNode {
25
  SEncoderNode* pNext;
26
  uint8_t*      data;
27
  uint32_t      size;
28
  uint32_t      pos;
29
};
30

31
struct SDecoderNode {
32
  SDecoderNode* pNext;
33
  uint8_t*      data;
34
  uint32_t      size;
35
  uint32_t      pos;
36
};
37

38
void tEncoderInit(SEncoder* pEncoder, uint8_t* data, uint32_t size) {
142,507,269✔
39
  if (data == NULL) size = 0;
142,507,269✔
40
  pEncoder->data = data;
142,507,269✔
41
  pEncoder->size = size;
142,507,269✔
42
  pEncoder->pos = 0;
142,507,269✔
43
  pEncoder->mList = NULL;
142,507,269✔
44
  pEncoder->eStack = NULL;
142,507,269✔
45
}
142,507,269✔
46

47
void tEncoderClear(SEncoder* pCoder) {
142,591,124✔
48
  for (SCoderMem* pMem = pCoder->mList; pMem; pMem = pCoder->mList) {
223,900,628✔
49
    pCoder->mList = pMem->next;
81,287,127✔
50
    taosMemoryFree(pMem);
81,287,127✔
51
  }
52
  memset(pCoder, 0, sizeof(*pCoder));
142,613,501✔
53
}
142,613,501✔
54

55
void tDecoderInit(SDecoder* pDecoder, uint8_t* data, uint32_t size) {
114,050,637✔
56
  pDecoder->data = data;
114,050,637✔
57
  pDecoder->size = size;
114,050,637✔
58
  pDecoder->pos = 0;
114,050,637✔
59
  pDecoder->mList = NULL;
114,050,637✔
60
  pDecoder->dStack = NULL;
114,050,637✔
61
}
114,050,637✔
62

63
void tDecoderClear(SDecoder* pCoder) {
116,299,457✔
64
  for (SCoderMem* pMem = pCoder->mList; pMem; pMem = pCoder->mList) {
298,091,098✔
65
    pCoder->mList = pMem->next;
181,748,986✔
66
    taosMemoryFree(pMem);
181,748,986✔
67
  }
68
  memset(pCoder, 0, sizeof(*pCoder));
116,342,112✔
69
}
116,342,112✔
70

71
int32_t tStartEncode(SEncoder* pCoder) {
162,161,039✔
72
  SEncoderNode* pNode;
73

74
  if (pCoder->data) {
162,161,039✔
75
    if (pCoder->size - pCoder->pos < sizeof(int32_t)) {
81,233,590!
76
      TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE);
×
77
    }
78

79
    pNode = tEncoderMalloc(pCoder, sizeof(*pNode));
81,288,533✔
80
    if (pNode == NULL) {
81,288,533!
UNCOV
81
      TAOS_RETURN(terrno);
×
82
    }
83

84
    pNode->data = pCoder->data;
81,288,533✔
85
    pNode->pos = pCoder->pos;
81,288,533✔
86
    pNode->size = pCoder->size;
81,288,533✔
87

88
    pCoder->data = pNode->data + pNode->pos + sizeof(int32_t);
81,288,533✔
89
    pCoder->pos = 0;
81,288,533✔
90
    pCoder->size = pNode->size - pNode->pos - sizeof(int32_t);
81,288,533✔
91

92
    pNode->pNext = pCoder->eStack;
81,288,533✔
93
    pCoder->eStack = pNode;
81,288,533✔
94
  } else {
95
    pCoder->pos += sizeof(int32_t);
80,927,449✔
96
  }
97

98
  return 0;
162,215,982✔
99
}
100

101
void tEndEncode(SEncoder* pCoder) {
162,310,476✔
102
  SEncoderNode* pNode;
103
  int32_t       len;
104

105
  if (pCoder->data) {
162,310,476✔
106
    pNode = pCoder->eStack;
81,279,131✔
107
    pCoder->eStack = pNode->pNext;
81,279,131✔
108

109
    len = pCoder->pos;
81,279,131✔
110

111
    pCoder->data = pNode->data;
81,279,131✔
112
    pCoder->size = pNode->size;
81,279,131✔
113
    pCoder->pos = pNode->pos;
81,279,131!
114

115
    int32_t ret = tEncodeI32(pCoder, len);
81,279,131✔
116

117
    pCoder->pos += len;
81,279,131✔
118
  }
119
}
162,310,476✔
120

121
int32_t tStartDecode(SDecoder* pCoder) {
139,781,703✔
122
  SDecoderNode* pNode;
123
  int32_t       len;
124

125
  TAOS_CHECK_RETURN(tDecodeI32(pCoder, &len));
139,811,538✔
126

127
  pNode = tDecoderMalloc(pCoder, sizeof(*pNode));
139,913,481✔
128
  if (pNode == NULL) {
139,913,481!
UNCOV
129
    TAOS_RETURN(terrno);
×
130
  }
131

132
  pNode->data = pCoder->data;
139,913,481✔
133
  pNode->pos = pCoder->pos;
139,913,481✔
134
  pNode->size = pCoder->size;
139,913,481✔
135

136
  pCoder->data = pNode->data + pNode->pos;
139,913,481✔
137
  pCoder->size = len;
139,913,481✔
138
  pCoder->pos = 0;
139,913,481✔
139

140
  pNode->pNext = pCoder->dStack;
139,913,481✔
141
  pCoder->dStack = pNode;
139,913,481✔
142

143
  return 0;
139,913,481✔
144
}
145

146
void tEndDecode(SDecoder* pCoder) {
139,805,504✔
147
  SDecoderNode* pNode;
148

149
  pNode = pCoder->dStack;
139,805,504✔
150
  pCoder->dStack = pNode->pNext;
139,805,504✔
151

152
  pCoder->data = pNode->data;
139,805,504✔
153
  pCoder->pos = pCoder->size + pNode->pos;
139,805,504✔
154
  pCoder->size = pNode->size;
139,805,504✔
155
}
139,805,504✔
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

© 2026 Coveralls, Inc