Skip to content

Commit

Permalink
memmove -> strncpy for some static string copies
Browse files Browse the repository at this point in the history
  • Loading branch information
jagerman committed May 12, 2023
1 parent a9b937b commit 9e5f296
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/oxen_ux_nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ unsigned int ui_menu_info_action(void) {
}

void ui_menu_info_display2(const char* line1, const char* line2) {
memmove(G_oxen_state.ux_info1, line1, sizeof(G_oxen_state.ux_info1) - 1);
memmove(G_oxen_state.ux_info2, line2, sizeof(G_oxen_state.ux_info2) - 1);
G_oxen_state.ux_info1[sizeof(G_oxen_state.ux_info1) - 1] = 0;
G_oxen_state.ux_info2[sizeof(G_oxen_state.ux_info2) - 1] = 0;
strncpy(G_oxen_state.ux_info1, line1, sizeof(G_oxen_state.ux_info1));
strncpy(G_oxen_state.ux_info2, line2, sizeof(G_oxen_state.ux_info2));
ux_flow_init(0, ux_flow_info, NULL);
}

Expand All @@ -130,8 +128,7 @@ static const char* processing_tx(void) {
}

void ui_menu_opentx_display(unsigned char final_step) {
memmove(G_oxen_state.ux_info1, processing_tx(), sizeof(G_oxen_state.ux_info1) - 1);
G_oxen_state.ux_info1[sizeof(G_oxen_state.ux_info1) - 1] = 0;
strncpy(G_oxen_state.ux_info1, processing_tx(), sizeof(G_oxen_state.ux_info1));

if (final_step)
ux_flow_init(0, ux_flow_info_icon4, NULL);
Expand Down Expand Up @@ -684,30 +681,30 @@ void ui_menu_any_pubaddr_display(unsigned char* pub_view,
switch (G_oxen_state.disp_addr_mode) {
case 0:
case DISP_MAIN:
memmove(G_oxen_state.ux_addr_type, "Regular address", 15);
strncpy(G_oxen_state.ux_addr_type, "Regular address", sizeof(G_oxen_state.ux_addr_type));
if (N_oxen_state->network_id == MAINNET)
memmove(G_oxen_state.ux_addr_info, "(mainnet)", 9);
strncpy(G_oxen_state.ux_addr_info, "(mainnet)", sizeof(G_oxen_state.ux_addr_info));
else if (N_oxen_state->network_id == TESTNET)
memmove(G_oxen_state.ux_addr_info, "(testnet)", 9);
strncpy(G_oxen_state.ux_addr_info, "(testnet)", sizeof(G_oxen_state.ux_addr_info));
else if (N_oxen_state->network_id == DEVNET)
memmove(G_oxen_state.ux_addr_info, "(devnet)", 8);
strncpy(G_oxen_state.ux_addr_info, "(devnet)", sizeof(G_oxen_state.ux_addr_info));
else if (N_oxen_state->network_id == FAKECHAIN)
memmove(G_oxen_state.ux_addr_info, "(fakenet)", 9);
strncpy(G_oxen_state.ux_addr_info, "(fakenet)", sizeof(G_oxen_state.ux_addr_info));
break;

case DISP_SUB:
memmove(G_oxen_state.ux_addr_type, "Subaddress", 10);
strncpy(G_oxen_state.ux_addr_type, "Subaddress", sizeof(G_oxen_state.ux_addr_type));
// Copy these out because they are in a union with the ux_addr_info string
unsigned int M = G_oxen_state.disp_addr_M;
unsigned int m = G_oxen_state.disp_addr_m;
snprintf(G_oxen_state.ux_addr_info, 31, "Maj/min: %d/%d", M, m);
break;

case DISP_INTEGRATED:
memmove(G_oxen_state.ux_addr_type, "Integr. address", 15);
strncpy(G_oxen_state.ux_addr_type, "Integr. address", sizeof(G_oxen_state.ux_addr_type));
// Copy the payment id into place *first*, before the label, because it overlaps with
// ux_addr_info
memmove(G_oxen_state.ux_addr_info + 9, G_oxen_state.payment_id, 16);
memmove(G_oxen_state.ux_addr_info + 9, G_oxen_state.payment_id, sizeof(G_oxen_state.payment_id));
memmove(G_oxen_state.ux_addr_info, "Pay. ID: ", 9);
break;
}
Expand Down

0 comments on commit 9e5f296

Please sign in to comment.