Skip to content

Commit

Permalink
UAVOMSPBridge: Use memcpy instead of strncpy where src len > dest (#2209
Browse files Browse the repository at this point in the history
)

GCC8 doesn't like it otherwise:

/home/mike/dev/dronin/flight/Modules/UAVOMSPBridge/UAVOMSPBridge.c: In function ‘msp_send_fc_variant’:
/home/mike/dev/dronin/flight/Modules/UAVOMSPBridge/UAVOMSPBridge.c:388:2: error: ‘strncpy’ output truncated before terminating nul
copying 4 bytes from a string of the same length [-Werror=stringop-truncation]
  strncpy(data.var.name, "DRON", 4);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mike/dev/dronin/flight/Modules/UAVOMSPBridge/UAVOMSPBridge.c: In function ‘msp_send_board_info’:
/home/mike/dev/dronin/flight/Modules/UAVOMSPBridge/UAVOMSPBridge.c:405:2: error: ‘strncpy’ output truncated copying 4 bytes from a
string of length 7 [-Werror=stringop-truncation]
  strncpy(data.board.name, DRONIN_TARGET, 4);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
  • Loading branch information
tracernz authored and mlyle committed Jul 29, 2018
1 parent 148f2e9 commit 4df9abe
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions flight/Modules/UAVOMSPBridge/UAVOMSPBridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ static void msp_send_fc_variant(struct msp_bridge *m)

memset(&data, 0, sizeof(data));

/* strncpy(data.var.name, "BTFL", 4);*/
strncpy(data.var.name, "DRON", 4);
memcpy(data.var.name, "DRON", 4);

msp_send(m, MSP_FC_VARIANT, data.buf, sizeof(data));
}
Expand All @@ -402,7 +401,7 @@ static void msp_send_board_info(struct msp_bridge *m)

memset(&data, 0, sizeof(data));

strncpy(data.board.name, DRONIN_TARGET, 4);
memcpy(data.board.name, DRONIN_TARGET, MIN(4, strlen(DRONIN_TARGET)));

msp_send(m, MSP_BOARD_INFO, data.buf, sizeof(data));
}
Expand Down

0 comments on commit 4df9abe

Please sign in to comment.