diff --git a/src/balance/src/balance.c b/src/balance/src/balance.c index 53638f1025a2d6b873d43a52b654b9efa3cfe132..0d2d9fc778b437b8fe0671487da097f6c531b204 100644 --- a/src/balance/src/balance.c +++ b/src/balance/src/balance.c @@ -118,6 +118,7 @@ static void balanceSwapVnodeGid(SVnodeGid *pVnodeGid1, SVnodeGid *pVnodeGid2) { } int32_t balanceAllocVnodes(SVgObj *pVgroup) { + static int32_t randIndex = 0; int32_t dnode = 0; int32_t vnodes = 0; @@ -160,7 +161,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { */ if (pVgroup->numOfVnodes == 1) { } else if (pVgroup->numOfVnodes == 2) { - if (rand() % 2 == 0) { + if (randIndex++ % 2 == 0) { balanceSwapVnodeGid(pVgroup->vnodeGid, pVgroup->vnodeGid + 1); } } else { diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 7046bc7725527dad38eb1975959f3d58f32294a3..1bd885466c995883b7487b1efcb1dadc8d7a5013 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -67,7 +67,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con taosEncryptPass((uint8_t *)pass, strlen(pass), secretEncrypt); } else { int outlen = 0; - int len = strlen(auth); + int len = (int)strlen(auth); char *base64 = (char *)base64_decode(auth, len, &outlen); if (base64 == NULL || outlen == 0) { tscError("invalid auth info:%s", auth); diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c index 62b1e0bb5cca71227dd08cf5e87980662455d167..62d4768db8a368daab105ac5abf6cf7607d5e52b 100644 --- a/src/common/src/ttimezone.c +++ b/src/common/src/ttimezone.c @@ -23,7 +23,9 @@ // TODO refactor to set the tz value through parameter void tsSetTimeZone() { SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); - uInfo("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); + if (cfg_timezone != NULL) { + uInfo("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); + } #ifdef WINDOWS char winStr[TSDB_LOCALE_LEN * 2]; diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 532f03bcb575ff6cc2cdb869d9376fe6226a8b60..e2b32145a3d66df30b53c9574e085c4cfbbe171c 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -710,10 +710,10 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) { pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval); pStatus->clusterCfg.maxtablesPerVnode = htonl(tsMaxTablePerVnode); pStatus->clusterCfg.maxVgroupsPerDb = htonl(tsMaxVgroupsPerDb); - strcpy(pStatus->clusterCfg.arbitrator, tsArbitrator); - strcpy(pStatus->clusterCfg.timezone, tsTimezone); - strcpy(pStatus->clusterCfg.locale, tsLocale); - strcpy(pStatus->clusterCfg.charset, tsCharset); + tstrncpy(pStatus->clusterCfg.arbitrator, tsArbitrator, TSDB_EP_LEN); + tstrncpy(pStatus->clusterCfg.timezone, tsTimezone, 64); + tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN); + tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN); vnodeBuildStatusMsg(pStatus); contLen = sizeof(SDMStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index f6249986fd33fd422c832d1247ca7ddb60e797d2..f828bc5a3d2c263997c7f80ac360a42cde8486f0 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -73,9 +73,9 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { pthread_mutex_lock(&pDb->mutex); pDb->vgListSize = VG_LIST_SIZE; pDb->vgList = calloc(pDb->vgListSize, sizeof(SVgObj *)); + pDb->numOfVgroups = 0; pthread_mutex_unlock(&pDb->mutex); - pDb->numOfVgroups = 0; pDb->numOfTables = 0; pDb->numOfSuperTables = 0; @@ -927,7 +927,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (quorum >= 0 && quorum != pDb->cfg.quorum) { mDebug("db:%s, quorum:%d change to %d", pDb->name, pDb->cfg.quorum, quorum); - newCfg.compression = quorum; + newCfg.quorum = quorum; } return newCfg; diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 7c01239490e7764c5bd9d045cc8a7ccc29d3dfad..edf8fe69455ae3bc2623ecb2fc1a323194d14f84 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -170,6 +170,7 @@ static void taosGetSystemTimezone() { fclose(f); + buf[sizeof(buf) - 1] = 0; char *lineEnd = strstr(buf, "\n"); if (lineEnd != NULL) { *lineEnd = 0; diff --git a/src/plugins/mqtt/src/mqttSystem.c b/src/plugins/mqtt/src/mqttSystem.c index 0259ea23eb66239b1e7fbfcb6d0243a16dabb32f..ab3f3f5d841bbfd5c2c2f7cd439c445ccaae93b2 100644 --- a/src/plugins/mqtt/src/mqttSystem.c +++ b/src/plugins/mqtt/src/mqttSystem.c @@ -70,14 +70,27 @@ int32_t mqttInitSystem() { recntStatus.port = strbetween("'1883'", "'", "'"); } - topicPath = strbetween(strstr(url, strstr(_begin_hostname, ":") != NULL ? recntStatus.port : recntStatus.hostname), - "/", "/"); - char* _topic = "+/+/+/"; - int _tpsize = strlen(topicPath) + strlen(_topic) + 1; - recntStatus.topic = calloc(1, _tpsize); - sprintf(recntStatus.topic, "/%s/%s", topicPath, _topic); - recntStatus.client_id = strlen(tsMqttBrokerClientId) < 3 ? tsMqttBrokerClientId : "taos_mqtt"; - mqttConnect = NULL; + char* portStr = recntStatus.hostname; + if (_begin_hostname != NULL) { + char* colonStr = strstr(_begin_hostname, ":"); + if (colonStr != NULL) { + portStr = recntStatus.port; + } + } + + char* topicStr = strstr(url, portStr); + if (topicStr != NULL) { + topicPath = strbetween(topicStr, "/", "/"); + char* _topic = "+/+/+/"; + int _tpsize = strlen(topicPath) + strlen(_topic) + 1; + recntStatus.topic = calloc(1, _tpsize); + sprintf(recntStatus.topic, "/%s/%s", topicPath, _topic); + recntStatus.client_id = strlen(tsMqttBrokerClientId) < 3 ? tsMqttBrokerClientId : "taos_mqtt"; + mqttConnect = NULL; + } else { + topicPath = NULL; + } + return rc; } diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 9abda0e1961ebea1112e7e6226cfa552155273a2..23f2e5f00ae339937a9812ca0deab901275e6a89 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -371,7 +371,7 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { serverAdd.sin_addr.s_addr = ip; serverAdd.sin_port = (uint16_t)htons(port); - if ((sockFd = (int)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { + if ((sockFd = (int)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 2) { uError("failed to open TCP socket: %d (%s)", errno, strerror(errno)); return -1; } @@ -382,7 +382,7 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { uError("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); taosCloseSocket(sockFd); return -1; - }; + } /* bind socket to server address */ if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) {