mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Replace all calls to strncpy with strlcpy, use strdup more, expose strlcat (#3866)
strlcpy doesn't zero the buffer and ensures null termination, just like snprintf strlcat is already used by mjs and it's a safe alternative to strcat, so it should be OK to expose to apps
This commit is contained in:
@@ -24,7 +24,7 @@ static void rpc_debug_app_tick_event_callback(void* context) {
|
||||
static void
|
||||
rpc_debug_app_format_hex(const uint8_t* data, size_t data_size, char* buf, size_t buf_size) {
|
||||
if(data == NULL || data_size == 0) {
|
||||
strncpy(buf, "<Data empty>", buf_size);
|
||||
strlcpy(buf, "<Data empty>", buf_size);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ static void rpc_debug_app_scene_input_error_code_result_callback(void* context)
|
||||
|
||||
void rpc_debug_app_scene_input_error_code_on_enter(void* context) {
|
||||
RpcDebugApp* app = context;
|
||||
strncpy(app->text_store, "666", TEXT_STORE_SIZE);
|
||||
strlcpy(app->text_store, "666", TEXT_STORE_SIZE);
|
||||
text_input_set_header_text(app->text_input, "Enter error code");
|
||||
text_input_set_validator(
|
||||
app->text_input, rpc_debug_app_scene_input_error_code_validator_callback, NULL);
|
||||
|
||||
@@ -7,7 +7,7 @@ static void rpc_debug_app_scene_input_error_text_result_callback(void* context)
|
||||
|
||||
void rpc_debug_app_scene_input_error_text_on_enter(void* context) {
|
||||
RpcDebugApp* app = context;
|
||||
strncpy(app->text_store, "I'm a scary error message!", TEXT_STORE_SIZE);
|
||||
strlcpy(app->text_store, "I'm a scary error message!", TEXT_STORE_SIZE);
|
||||
text_input_set_header_text(app->text_input, "Enter error text");
|
||||
text_input_set_result_callback(
|
||||
app->text_input,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
void rpc_debug_app_scene_receive_data_exchange_on_enter(void* context) {
|
||||
RpcDebugApp* app = context;
|
||||
strncpy(app->text_store, "Received data will appear here...", TEXT_STORE_SIZE);
|
||||
strlcpy(app->text_store, "Received data will appear here...", TEXT_STORE_SIZE);
|
||||
|
||||
text_box_set_text(app->text_box, app->text_store);
|
||||
text_box_set_font(app->text_box, TextBoxFontHex);
|
||||
|
||||
Reference in New Issue
Block a user