Skip to content

Commit 4fc5f26

Browse files
committed
fix crash in jd_settings_get_bin()
1 parent 73a4976 commit 4fc5f26

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

main/flash.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ static void nvs_init(void) {
1616
}
1717

1818
int jd_settings_get_bin(const char *key, void *dst, unsigned space) {
19-
size_t len;
19+
size_t len = space;
2020

2121
nvs_init();
2222

2323
int err = nvs_get_blob(flash_handle, key, dst, &len);
2424
if (err == ESP_ERR_NVS_NOT_FOUND)
25-
return -1;
25+
err = -1;
26+
else if (err == 0 || err == ESP_ERR_NVS_INVALID_LENGTH)
27+
err = len;
28+
else
29+
JD_PANIC();
2630

27-
if (err == ESP_ERR_NVS_INVALID_LENGTH || err == 0)
28-
return len;
29-
30-
JD_PANIC();
31+
return err;
3132
}
3233

3334
int jd_settings_set_bin(const char *key, const void *val, unsigned size) {

0 commit comments

Comments
 (0)