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

taosdata / TDengine / #3768

28 Mar 2025 10:15AM UTC coverage: 33.726% (-0.3%) from 33.993%
#3768

push

travis-ci

happyguoxy
test:alter lcov result

144891 of 592084 branches covered (24.47%)

Branch coverage included in aggregate %.

218795 of 486283 relevant lines covered (44.99%)

765715.29 hits per line

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

53.68
/source/util/src/tversion.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 "tversion.h"
18
#include "taoserror.h"
19

20
int32_t taosVersionStrToInt(const char *vstr, int32_t *vint) {
235,003✔
21
  int32_t code = 0;
235,003✔
22
  if (vstr == NULL) {
235,003!
23
    return terrno = TSDB_CODE_INVALID_VERSION_STRING;
×
24
  }
25

26
  int32_t vnum[4] = {0};
235,003✔
27
  int32_t len = strlen(vstr);
235,003✔
28
  char    tmp[16] = {0};
235,003✔
29
  int32_t vpos = 0;
235,003✔
30

31
  for (int32_t spos = 0, tpos = 0; spos < len && vpos < 4; ++spos) {
2,115,005!
32
    if (vstr[spos] != '.') {
1,880,010✔
33
      tmp[spos - tpos] = vstr[spos];
940,004✔
34
    } else {
35
      code = taosStr2int32(tmp, &vnum[vpos]);
940,006✔
36
      if (code != 0) {
939,998!
37
        return code;
×
38
      }
39
      memset(tmp, 0, sizeof(tmp));
939,998✔
40
      vpos++;
939,998✔
41
      tpos = spos + 1;
939,998✔
42
    }
43
  }
44

45
  if ('\0' != tmp[0] && vpos < 4) {
234,995!
46
    code = taosStr2int32(tmp, &vnum[vpos]);
×
47
    if (code != 0) {
×
48
      return code;
×
49
    }
50
  }
51

52
  if (vnum[0] <= 0) {
234,995!
53
    return terrno = TSDB_CODE_INVALID_VERSION_STRING;
×
54
  }
55

56
  *vint = vnum[0] * 1000000 + vnum[1] * 10000 + vnum[2] * 100 + vnum[3];
234,995✔
57
  return 0;
234,995✔
58
}
59

60
int32_t taosVersionIntToStr(int32_t vint, char *vstr, int32_t len) {
×
61
  int32_t s1 = (vint % 100000000) / 1000000;
×
62
  int32_t s2 = (vint % 1000000) / 10000;
×
63
  int32_t s3 = (vint % 10000) / 100;
×
64
  int32_t s4 = vint % 100;
×
65
  if (s1 <= 0) {
×
66
    return terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
×
67
  }
68

69
  snprintf(vstr, len, "%02d.%02d.%02d.%02d", s1, s2, s3, s4);
×
70
  return 0;
×
71
}
72

73
int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t comparedSegments) {
230,599✔
74
  switch (comparedSegments) {
230,599!
75
    case 4:
×
76
      break;
×
77
    case 3:
230,599✔
78
      clientVer /= 100;
230,599✔
79
      serverVer /= 100;
230,599✔
80
      break;
230,599✔
81
    case 2:
×
82
      clientVer /= 10000;
×
83
      serverVer /= 10000;
×
84
      break;
×
85
    case 1:
×
86
      clientVer /= 1000000;
×
87
      serverVer /= 1000000;
×
88
      break;
×
89
    default:
×
90
      return TSDB_CODE_INVALID_VERSION_NUMBER;
×
91
  }
92

93
  if (clientVer == serverVer) {
230,599✔
94
    return 0;
230,598✔
95
  } else {
96
    return TSDB_CODE_VERSION_NOT_COMPATIBLE;
1✔
97
  }
98
}
99

100
int32_t taosCheckVersionCompatibleFromStr(const char *pClientVersion, const char *pServerVersion,
3,367✔
101
                                          int32_t comparedSegments) {
102
  int32_t clientVersion = 0;
3,367✔
103
  int32_t serverVersion = 0;
3,367✔
104
  int32_t code = taosVersionStrToInt(pClientVersion, &clientVersion);
3,367✔
105
  if (TSDB_CODE_SUCCESS == code) {
3,367!
106
    code = taosVersionStrToInt(pServerVersion, &serverVersion);
3,367✔
107
  }
108
  if (TSDB_CODE_SUCCESS == code) {
3,367!
109
    code = taosCheckVersionCompatible(clientVersion, serverVersion, comparedSegments);
3,367✔
110
  }
111
  return code;
3,367✔
112
}
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