Skip to content

Commit

Permalink
Make sure to copy null terminator byte in dual channel code (#1272)
Browse files Browse the repository at this point in the history
As @madolson pointed out, these do have proper null terminators. This
cleans them up to follow the rest of the code which copies the last byte
explicitly, which should help reduce cognitive load and make it more
resilient should code refactors occur (e.g. non-static allocation of
memory, changes to other functions).

---------

Signed-off-by: Jacob Murphy <[email protected]>
  • Loading branch information
murphyjacob4 authored Nov 8, 2024
1 parent 07b3e7a commit e972d56
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ static int dualChannelReplHandleEndOffsetResponse(connection *conn, sds *err) {

/* Initiate repl_provisional_primary to act as this replica temp primary until RDB is loaded */
server.repl_provisional_primary.conn = server.repl_transfer_s;
memcpy(server.repl_provisional_primary.replid, primary_replid, CONFIG_RUN_ID_SIZE);
memcpy(server.repl_provisional_primary.replid, primary_replid, sizeof(server.repl_provisional_primary.replid));
server.repl_provisional_primary.reploff = reploffset;
server.repl_provisional_primary.read_reploff = reploffset;
server.repl_provisional_primary.dbid = dbid;
Expand Down Expand Up @@ -4269,7 +4269,7 @@ void replicationResurrectProvisionalPrimary(void) {
/* Create a primary client, but do not initialize the read handler yet, as this replica still has a local buffer to
* drain. */
replicationCreatePrimaryClientWithHandler(server.repl_transfer_s, server.repl_provisional_primary.dbid, NULL);
memcpy(server.primary->replid, server.repl_provisional_primary.replid, CONFIG_RUN_ID_SIZE);
memcpy(server.primary->replid, server.repl_provisional_primary.replid, sizeof(server.repl_provisional_primary.replid));
server.primary->reploff = server.repl_provisional_primary.reploff;
server.primary->read_reploff = server.repl_provisional_primary.read_reploff;
server.primary_repl_offset = server.primary->reploff;
Expand Down

0 comments on commit e972d56

Please sign in to comment.