Skip to content

Commit

Permalink
rg_network: Replaced strncpy with memccpy
Browse files Browse the repository at this point in the history
the ssid and passwords do not have trailing 0s in esp-idf, so we have to match but gcc complains when I use strncpy.
  • Loading branch information
ducalex committed Mar 11, 2024
1 parent 0eace30 commit 15139cb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions components/retro-go/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ component_compile_options(
-Wno-unused-function
)
set_source_files_properties(
rg_audio.c rg_display.c
rg_audio.c rg_display.c rg_utils.c rg_surface.c
PROPERTIES COMPILE_FLAGS
-O3
-O2
)

if (IDF_VERSION_MAJOR EQUAL 5)
Expand Down
6 changes: 3 additions & 3 deletions components/retro-go/rg_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ bool rg_network_wifi_load_config(int slot)
char *ptr;

if ((ptr = rg_settings_get_string(NS_WIFI, key_ssid, NULL)))
strncpy(config.ssid, ptr, 32), free(ptr);
memccpy(config.ssid, ptr, 0, 32), free(ptr);
if ((ptr = rg_settings_get_string(NS_WIFI, key_password, NULL)))
strncpy(config.password, ptr, 64), free(ptr);
memccpy(config.password, ptr, 0, 64), free(ptr);
config.channel = rg_settings_get_number(NS_WIFI, key_channel, 0);
config.ap_mode = rg_settings_get_number(NS_WIFI, key_mode, 0);

Expand Down Expand Up @@ -193,7 +193,7 @@ void rg_network_wifi_stop(void)
RG_ASSERT(initialized, "Please call rg_network_init() first");
esp_wifi_stop();
rg_task_delay(100);
memset(network.name, 0, 32);
memset(network.name, 0, sizeof(network.name));
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion components/retro-go/rg_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef enum

typedef struct
{
char name[32];
char name[33];
char ip_addr[16];
int channel, rssi;
int state;
Expand Down
2 changes: 1 addition & 1 deletion components/retro-go/rg_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ uint32_t rg_crc32(uint32_t crc, const uint8_t *buf, size_t len)
* This function is the SuperFastHash from:
* http://www.azillionmonkeys.com/qed/hash.html
*/
uint32_t rg_hash(const char *data, size_t len)
IRAM_ATTR uint32_t rg_hash(const char *data, size_t len)
{
#define get16bits(d) (*((const uint16_t *)(d)))

Expand Down

0 comments on commit 15139cb

Please sign in to comment.