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

taosdata / TDengine / #4864

26 Nov 2025 05:46AM UTC coverage: 64.548% (+0.009%) from 64.539%
#4864

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

769 of 945 new or added lines in 33 files covered. (81.38%)

3006 existing lines in 116 files now uncovered.

158227 of 245129 relevant lines covered (64.55%)

111826500.07 hits per line

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

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

26
  int32_t vnum[4] = {0};
2,072,826,710✔
27
  int32_t len = strlen(vstr);
2,072,834,322✔
28
  char    tmp[16] = {0};
2,072,834,322✔
29
  int32_t vpos = 0;
2,072,885,322✔
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,072,951,583✔
46
    code = taosStr2int32(tmp, &vnum[vpos]);
×
UNCOV
47
    if (code != 0) {
×
48
      return code;
×
49
    }
50
  }
51

52
  if (vnum[0] <= 0) {
2,072,910,276✔
53
    return terrno = TSDB_CODE_INVALID_VERSION_STRING;
×
54
  }
55

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

93
  if (clientVer == serverVer) {
2,061,880,270✔
94
    return 0;
2,061,850,931✔
95
  } else {
96
    return TSDB_CODE_VERSION_NOT_COMPATIBLE;
29,594✔
97
  }
98
}
99

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