• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

taosdata / TDengine / #4917

07 Jan 2026 03:52PM UTC coverage: 65.42% (+0.02%) from 65.402%
#4917

push

travis-ci

web-flow
merge: from main to 3.0 branch #34204

31 of 34 new or added lines in 2 files covered. (91.18%)

819 existing lines in 129 files now uncovered.

202679 of 309814 relevant lines covered (65.42%)

116724351.99 hits per line

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

64.86
/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) {
2,147,483,647✔
21
  int32_t code = 0;
2,147,483,647✔
22
  if (vstr == NULL) {
2,147,483,647✔
23
    return terrno = TSDB_CODE_INVALID_VERSION_STRING;
×
24
  }
25

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

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

45
  if ('\0' != tmp[0] && vpos < 4) {
2,147,483,647✔
46
    code = taosStr2int32(tmp, &vnum[vpos]);
×
47
    if (code != 0) {
22✔
48
      return code;
×
49
    }
50
  }
51

52
  if (vnum[0] <= 0) {
2,147,483,647✔
53
    return terrno = TSDB_CODE_INVALID_VERSION_STRING;
×
54
  }
55

56
  *vint = vnum[0] * 1000000 + vnum[1] * 10000 + vnum[2] * 100 + vnum[3];
2,147,483,647✔
57
  return 0;
2,147,483,647✔
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) {
2,147,483,647✔
74
  switch (comparedSegments) {
2,147,483,647✔
75
    case 4:
×
76
      break;
×
77
    case 3:
2,147,483,647✔
78
      clientVer /= 100;
2,147,483,647✔
79
      serverVer /= 100;
2,147,483,647✔
80
      break;
2,147,483,647✔
81
    case 2:
×
82
      clientVer /= 10000;
×
83
      serverVer /= 10000;
×
84
      break;
×
85
    case 1:
×
86
      clientVer /= 1000000;
×
87
      serverVer /= 1000000;
×
88
      break;
×
89
    default:
74✔
90
      return TSDB_CODE_INVALID_VERSION_NUMBER;
74✔
91
  }
92

93
  if (clientVer == serverVer) {
2,147,483,647✔
94
    return 0;
2,147,483,647✔
95
  } else {
96
    return TSDB_CODE_VERSION_NOT_COMPATIBLE;
89,541✔
97
  }
98
}
99

100
int32_t taosCheckEditionCompatible(const char *pClientVersion, const char *pServerVersion) {
3,966,402✔
101
  const char *pClientEdition = strrchr(pClientVersion, '.');
3,966,402✔
102
  const char *pServerEdition = strrchr(pServerVersion, '.');
3,966,402✔
103

104
  // according to current version number design, the last segment is edition info.
105
  // the following checks are based on this assumption, if the design changes, the
106
  // checks should be updated accordingly
107

108
  if ((pServerEdition == NULL) || (pClientEdition == NULL)) {
3,966,402✔
UNCOV
109
    return TSDB_CODE_EDITION_NOT_COMPATIBLE;
×
110
  }
111
  
112
  if (strcmp(pServerEdition, pClientEdition) != 0) {
3,966,414✔
113
    return TSDB_CODE_EDITION_NOT_COMPATIBLE;
×
114
  }
115

116
  return TSDB_CODE_SUCCESS;
3,966,414✔
117
}
118

119
int32_t taosCheckVersionCompatibleFromStr(const char *pClientVersion, const char *pServerVersion,
3,966,414✔
120
                                          int32_t comparedSegments) {
121
  int32_t clientVersion = 0;
3,966,414✔
122
  int32_t serverVersion = 0;
3,966,414✔
123
  int32_t code = taosVersionStrToInt(pClientVersion, &clientVersion);
3,966,414✔
124
  if (TSDB_CODE_SUCCESS == code) {
3,966,414✔
125
    code = taosVersionStrToInt(pServerVersion, &serverVersion);
3,966,414✔
126
  }
127
  if (TSDB_CODE_SUCCESS == code) {
3,966,414✔
128
    code = taosCheckVersionCompatible(clientVersion, serverVersion, comparedSegments);
3,966,414✔
129
  }
130
  if (TSDB_CODE_SUCCESS == code) {
3,966,414✔
131
    code = taosCheckEditionCompatible(pClientVersion, pServerVersion);
3,966,414✔
132
  }
133
  return code;
3,966,414✔
134
}
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