From 2498e0fc1ff040711f7b7c3b5ce7c585f045850a Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran <105669860+msotheeswaran@users.noreply.github.com> Date: Thu, 15 Dec 2022 15:49:44 -0500 Subject: [PATCH] fix macos build warnings/ remove 32 bit CI run (#522) * fix macos build warnings * remove 32 bit ci run as we no longer support it --- .github/workflows/ci.yml | 12 ------------ src/config.cpp | 4 ++-- src/dict.cpp | 2 +- src/endianconv.c | 6 +++--- src/keydb-diagnostic-tool.cpp | 2 +- src/networking.cpp | 6 +++--- src/redis-cli.c | 20 ++++++++++---------- src/replication.cpp | 2 +- src/server.cpp | 14 +++++++------- src/server.h | 6 ++++++ src/t_nhash.cpp | 2 +- src/ziplist.c | 22 +++++++++++----------- src/zmalloc.cpp | 2 +- 13 files changed, 47 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bafe45fc2..2be17b176 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,15 +69,3 @@ jobs: sudo apt-get -y remove libzstd || true sudo apt-get -y install uuid-dev libcurl4-openssl-dev libbz2-dev zlib1g-dev libsnappy-dev liblz4-dev libzstd-dev libgflags-dev make KEYDB_CFLAGS='-Werror' KEYDB_CXXFLAGS='-Werror' MALLOC=libc -j2 - build-ubuntu-32bit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - name: make - run: | - sudo dpkg --add-architecture i386 - sudo apt-get update - sudo apt-get -y install gcc-multilib g++-multilib libc6-dev-i386 lib32z1 uuid-dev:i386 libcurl4-openssl-dev:i386 - make KEYDB_CFLAGS='-Werror' KEYDB_CXXFLAGS='-Werror' 32bit -j2 diff --git a/src/config.cpp b/src/config.cpp index 5e01630a5..253f0726a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2587,7 +2587,7 @@ static int updateMaxclients(long long val, long long prev, const char **err) { adjustOpenFilesLimit(); if (g_pserver->maxclients != val) { static char msg[128]; - sprintf(msg, "The operating system is not able to handle the specified number of clients, try with %d", g_pserver->maxclients); + snprintf(msg, 128, "The operating system is not able to handle the specified number of clients, try with %d", g_pserver->maxclients); *err = msg; if (g_pserver->maxclients > prev) { g_pserver->maxclients = prev; @@ -2626,7 +2626,7 @@ static int updateMaxclients(long long val, long long prev, const char **err) { if (res != AE_OK){ static char msg[128]; - sprintf(msg, "Failed to post the request to change setsize for Thread %d", iel); + snprintf(msg, 128,"Failed to post the request to change setsize for Thread %d", iel); *err = msg; return 0; } diff --git a/src/dict.cpp b/src/dict.cpp index b29c0e24b..527e62d31 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -1577,7 +1577,7 @@ char *stringFromLongLong(long long value) { int len; char *s; - len = sprintf(buf,"%lld",value); + len = snprintf(buf,32,"%lld",value); s = zmalloc(len+1); memcpy(s, buf, len); s[len] = '\0'; diff --git a/src/endianconv.c b/src/endianconv.c index 98ed405a5..8b6a216af 100644 --- a/src/endianconv.c +++ b/src/endianconv.c @@ -112,15 +112,15 @@ int endianconvTest(int argc, char *argv[], int accurate) { UNUSED(argv); UNUSED(accurate); - sprintf(buf,"ciaoroma"); + snprintf(buf,32,"ciaoroma"); memrev16(buf); printf("%s\n", buf); - sprintf(buf,"ciaoroma"); + snprintf(buf,32,"ciaoroma"); memrev32(buf); printf("%s\n", buf); - sprintf(buf,"ciaoroma"); + snprintf(buf,32,"ciaoroma"); memrev64(buf); printf("%s\n", buf); diff --git a/src/keydb-diagnostic-tool.cpp b/src/keydb-diagnostic-tool.cpp index 74b46ce83..a06a690b8 100644 --- a/src/keydb-diagnostic-tool.cpp +++ b/src/keydb-diagnostic-tool.cpp @@ -904,7 +904,7 @@ int main(int argc, const char **argv) { while (self_threads < config.max_threads) { for (int i = 0; i < config.numclients; i++) { - sprintf(command, "SET %d %s\r\n", self_threads * config.numclients + i, set_value); + snprintf(command, 63, "SET %d %s\r\n", self_threads * config.numclients + i, set_value); createClient(command, strlen(command), NULL,self_threads); } diff --git a/src/networking.cpp b/src/networking.cpp index dc0abd79c..b005491c5 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -145,7 +145,7 @@ client *createClient(connection *conn, int iel) { client_id = g_pserver->next_client_id.fetch_add(1); c->iel = iel; c->id = client_id; - sprintf(c->lock.szName, "client %" PRIu64, client_id); + snprintf(c->lock.szName, 56, "client %" PRIu64, client_id); c->resp = 2; c->conn = conn; c->name = NULL; @@ -777,11 +777,11 @@ void setDeferredAggregateLen(client *c, void *node, long length, char prefix) { * we return NULL in addReplyDeferredLen() */ if (node == NULL) return; char lenstr[128]; - size_t lenstr_len = sprintf(lenstr, "%c%ld\r\n", prefix, length); + size_t lenstr_len = snprintf(lenstr, 128, "%c%ld\r\n", prefix, length); setDeferredReply(c, node, lenstr, lenstr_len); } else { char lenstr[128]; - int lenstr_len = sprintf(lenstr, "%c%ld\r\n", prefix, length); + int lenstr_len = snprintf(lenstr, 128, "%c%ld\r\n", prefix, length); size_t idxSplice = (size_t)node; serverAssert(idxSplice <= c->replyAsync->used); diff --git a/src/redis-cli.c b/src/redis-cli.c index a2ed82d39..71015c432 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -6835,17 +6835,17 @@ void bytesToHuman(char *s, long long n) { } if (n < 1024) { /* Bytes */ - sprintf(s,"%lldB",n); + snprintf(s,256,"%lldB",n); return; } else if (n < (1024*1024)) { d = (double)n/(1024); - sprintf(s,"%.2fK",d); + snprintf(s,256,"%.2fK",d); } else if (n < (1024LL*1024*1024)) { d = (double)n/(1024*1024); - sprintf(s,"%.2fM",d); + snprintf(s,256,"%.2fM",d); } else if (n < (1024LL*1024*1024*1024)) { d = (double)n/(1024LL*1024*1024); - sprintf(s,"%.2fG",d); + snprintf(s,256,"%.2fG",d); } } @@ -6875,12 +6875,12 @@ static void statMode(void) { for (j = 0; j < 20; j++) { long k; - sprintf(buf,"db%d:keys",j); + snprintf(buf,64,"db%d:keys",j); k = getLongInfoField(reply->str,buf); if (k == LONG_MIN) continue; aux += k; } - sprintf(buf,"%ld",aux); + snprintf(buf,64,"%ld",aux); printf("%-11s",buf); /* Used memory */ @@ -6890,23 +6890,23 @@ static void statMode(void) { /* Clients */ aux = getLongInfoField(reply->str,"connected_clients"); - sprintf(buf,"%ld",aux); + snprintf(buf,64,"%ld",aux); printf(" %-8s",buf); /* Blocked (BLPOPPING) Clients */ aux = getLongInfoField(reply->str,"blocked_clients"); - sprintf(buf,"%ld",aux); + snprintf(buf,64,"%ld",aux); printf("%-8s",buf); /* Requests */ aux = getLongInfoField(reply->str,"total_commands_processed"); - sprintf(buf,"%ld (+%ld)",aux,requests == 0 ? 0 : aux-requests); + snprintf(buf,64,"%ld (+%ld)",aux,requests == 0 ? 0 : aux-requests); printf("%-19s",buf); requests = aux; /* Connections */ aux = getLongInfoField(reply->str,"total_connections_received"); - sprintf(buf,"%ld",aux); + snprintf(buf,64,"%ld",aux); printf(" %-12s",buf); /* Children */ diff --git a/src/replication.cpp b/src/replication.cpp index 499bb533e..7afe1d22b 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -1142,7 +1142,7 @@ public: } }; -int rdbSaveSnapshotForReplication(struct rdbSaveInfo *rsi) { +int rdbSaveSnapshotForReplication(rdbSaveInfo *rsi) { // TODO: This needs to be on a background thread int retval = C_OK; serverAssert(GlobalLocksAcquired()); diff --git a/src/server.cpp b/src/server.cpp index 59bc7c9a3..3a1fbbede 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -5472,25 +5472,25 @@ void bytesToHuman(char *s, unsigned long long n) { if (n < 1024) { /* Bytes */ - sprintf(s,"%lluB",n); + snprintf(s,256,"%lluB",n); } else if (n < (1024*1024)) { d = (double)n/(1024); - sprintf(s,"%.2fK",d); + snprintf(s,256,"%.2fK",d); } else if (n < (1024LL*1024*1024)) { d = (double)n/(1024*1024); - sprintf(s,"%.2fM",d); + snprintf(s,256,"%.2fM",d); } else if (n < (1024LL*1024*1024*1024)) { d = (double)n/(1024LL*1024*1024); - sprintf(s,"%.2fG",d); + snprintf(s,256,"%.2fG",d); } else if (n < (1024LL*1024*1024*1024*1024)) { d = (double)n/(1024LL*1024*1024*1024); - sprintf(s,"%.2fT",d); + snprintf(s,256,"%.2fT",d); } else if (n < (1024LL*1024*1024*1024*1024*1024)) { d = (double)n/(1024LL*1024*1024*1024*1024); - sprintf(s,"%.2fP",d); + snprintf(s,256,"%.2fP",d); } else { /* Let's hope we never need this */ - sprintf(s,"%lluB",n); + snprintf(s,256,"%lluB",n); } } diff --git a/src/server.h b/src/server.h index d60e81b5d..eee584f2d 100644 --- a/src/server.h +++ b/src/server.h @@ -1909,6 +1909,12 @@ struct MasterSaveInfo { masterhost = sdsstring(sdsdup(mi.masterhost)); masterport = mi.masterport; } + MasterSaveInfo(const MasterSaveInfo &other) { + masterhost = other.masterhost; + masterport = other.masterport; + memcpy(master_replid, other.master_replid, sizeof(master_replid)); + master_initial_offset = other.master_initial_offset; + } MasterSaveInfo &operator=(const MasterSaveInfo &other) { masterhost = other.masterhost; diff --git a/src/t_nhash.cpp b/src/t_nhash.cpp index 9cf4d81ea..b0d4b9dcf 100644 --- a/src/t_nhash.cpp +++ b/src/t_nhash.cpp @@ -263,7 +263,7 @@ sds writeJsonValue(sds output, const char *valIn, size_t cchIn) { serverAssert(!FSimpleJsonEscapeCh(valIn[ich])); if (FExtendedJsonEscapeCh(valIn[ich])) { dst[ichDst++] = '\\'; dst[ichDst++] = 'u'; - sprintf(dst + ichDst, "%4x", valIn[ich]); + snprintf(dst + ichDst, cchIn+cchEscapeExtra-ichDst, "%4x", valIn[ich]); ichDst += 4; } else { dst[ichDst++] = valIn[ich]; diff --git a/src/ziplist.c b/src/ziplist.c index dc828428b..2a6dcf5b5 100644 --- a/src/ziplist.c +++ b/src/ziplist.c @@ -1704,17 +1704,17 @@ static unsigned char *createIntList() { unsigned char *zl = ziplistNew(); char buf[32]; - sprintf(buf, "100"); + snprintf(buf, 32, "100"); zl = ziplistPush(zl, (unsigned char*)buf, strlen(buf), ZIPLIST_TAIL); - sprintf(buf, "128000"); + snprintf(buf, 32, "128000"); zl = ziplistPush(zl, (unsigned char*)buf, strlen(buf), ZIPLIST_TAIL); - sprintf(buf, "-100"); + snprintf(buf, 32, "-100"); zl = ziplistPush(zl, (unsigned char*)buf, strlen(buf), ZIPLIST_HEAD); - sprintf(buf, "4294967296"); + snprintf(buf, 32, "4294967296"); zl = ziplistPush(zl, (unsigned char*)buf, strlen(buf), ZIPLIST_HEAD); - sprintf(buf, "non integer"); + snprintf(buf, 32, "non integer"); zl = ziplistPush(zl, (unsigned char*)buf, strlen(buf), ZIPLIST_TAIL); - sprintf(buf, "much much longer non integer"); + snprintf(buf, 32, "much much longer non integer"); zl = ziplistPush(zl, (unsigned char*)buf, strlen(buf), ZIPLIST_TAIL); return zl; } @@ -2228,7 +2228,7 @@ int ziplistTest(int argc, char **argv, int accurate) { char buf[32]; int i,len; for (i = 0; i < 1000; i++) { - len = sprintf(buf,"%d",i); + len = snprintf(buf,32,"%d",i); zl = ziplistPush(zl,(unsigned char*)buf,len,ZIPLIST_TAIL); } for (i = 0; i < 1000; i++) { @@ -2375,13 +2375,13 @@ int ziplistTest(int argc, char **argv, int accurate) { } else { switch(rand() % 3) { case 0: - buflen = sprintf(buf,"%lld",(0LL + rand()) >> 20); + buflen = snprintf(buf,1024,"%lld",(0LL + rand()) >> 20); break; case 1: - buflen = sprintf(buf,"%lld",(0LL + rand())); + buflen = snprintf(buf,1024,"%lld",(0LL + rand())); break; case 2: - buflen = sprintf(buf,"%lld",(0LL + rand()) << 20); + buflen = snprintf(buf,1024,"%lld",(0LL + rand()) << 20); break; default: assert(NULL); @@ -2410,7 +2410,7 @@ int ziplistTest(int argc, char **argv, int accurate) { assert(ziplistGet(p,&sstr,&slen,&sval)); if (sstr == NULL) { - buflen = sprintf(buf,"%lld",sval); + buflen = snprintf(buf,1024,"%lld",sval); } else { buflen = slen; memcpy(buf,sstr,buflen); diff --git a/src/zmalloc.cpp b/src/zmalloc.cpp index dac6f6631..d854cb7fe 100644 --- a/src/zmalloc.cpp +++ b/src/zmalloc.cpp @@ -521,7 +521,7 @@ int jemalloc_purge() { unsigned narenas = 0; size_t sz = sizeof(unsigned); if (!je_mallctl("arenas.narenas", &narenas, &sz, NULL, 0)) { - sprintf(tmp, "arena.%d.purge", narenas); + snprintf(tmp, 32, "arena.%d.purge", narenas); if (!je_mallctl(tmp, NULL, 0, NULL, 0)) return 0; }