LoadStoreError while concatenating strings
Posted: Sun Mar 24, 2019 7:00 am
- Hardware: ESP32-WROOM
- ESP-IDF: Latest
Code: Select all
File list has been requested...
Beginning of serialization...
5 files has been found
SPIFFS: free 785 KB of 934 KB
-----------------------------------
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x4000c52a PS : 0x00060e30 A0 : 0x80108771 A1 : 0x3ffee730
A2 : 0x3ffee750 A3 : 0x00000011 A4 : 0x00000009 A5 : 0x3ffee770
A6 : 0x00000000 A7 : 0x3a22657a A8 : 0x00000000 A9 : 0x3ffee770
A10 : 0x00000011 A11 : 0x00000001 A12 : 0x800949ac A13 : 0x3ffbee90
A14 : 0x00000003 A15 : 0x00060023 SAR : 0x00000008 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000011 LBEG : 0x4000c349 LEND : 0x4000c36b LCOUNT : 0xffffffff
ELF file SHA256: 46648d301515cb32c0ffb99f1bacfd742fc5c2b20ef8b168dda85277fef54312
Backtrace: 0x4000c52a:0x3ffee730 0x4010876e:0x3ffee750 0x401a77b7:0x3ffee790 0x401a7e99:0x3ffee7d0 0x401a7f2d:0x3ffee860 0x401a8418:0x3ffee880 0x401a6932:0x3ffee8a0 0x401a69a4:0x3ffee8e0 0x40094e05:0x3ffee900
0x4010876e: http_list_files at /home/dmitrij999/esp/a2dp_sink/main/main.c:711 (discriminator 9)
0x401a77b7: httpd_uri at /home/dmitrij999/esp/esp-idf/components/esp_http_server/src/httpd_uri.c:311
0x401a7e99: httpd_parse_req at /home/dmitrij999/esp/esp-idf/components/esp_http_server/src/httpd_parse.c:699
0x401a7f2d: httpd_req_new at /home/dmitrij999/esp/esp-idf/components/esp_http_server/src/httpd_parse.c:699
0x401a8418: httpd_sess_process at /home/dmitrij999/esp/esp-idf/components/esp_http_server/src/httpd_sess.c:326
0x401a6932: httpd_server at /home/dmitrij999/esp/esp-idf/components/esp_http_server/src/httpd_main.c:113
0x401a69a4: httpd_thread at /home/dmitrij999/esp/esp-idf/components/esp_http_server/src/httpd_main.c:113
0x40094e05: vPortTaskWrapper at /home/dmitrij999/esp/esp-idf/components/freertos/port.c:403
Here is the code stub:
Code: Select all
esp_err_t http_list_files(httpd_req_t *req) {
spiffs_file *f_list;
char * json_string = NULL;
int char_ptr = 0;
//string json;
char buf;
int ret;
printf("File list has been requested...\n");
/*
if ((ret = httpd_req_recv(req, &buf, 1)) <= 0) {
if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
httpd_resp_send_408(req);
}
return ESP_FAIL;
}
*/
printf("Beginning of serialization...\n");
int files = count_files("/spiffs", NULL);
json_string = malloc(files*720);
if (json_string == NULL) {
printf("No memory!");
return ESP_FAIL;
}
printf("%d files has been found\n", files);
//strcat(json_string, "[");
f_list = file_list("/spiffs", NULL);
if (f_list == NULL) {
httpd_resp_send_500(req);
//httpd_resp_set_status(req, "502");
const char *resp = "Internal Server Error";
httpd_resp_send(req, resp, strlen(resp));
return ESP_FAIL;
}
/*
for (int i = 0; i < files; i++) {
printf("%d %d %s\r\n",
f_list[i].type,
f_list[i].size,
f_list[i].path
//tbuffer,
//ent->d_name
);
}
*/
//printf("Array size: %d", sizeof(json_string));
//strcat(json_string, "[");
json_string = "[";
myStrcat(json_string, "{}]");
/*
for (int i = 0; i < files-1; i++) {
json_string = json_string + "{\"file\":\"";
strcat(json_string, f_list[i].path);
strcat(json_string, "\",\"size\":");
strcat(json_string, f_list[i].size);
strcat(json_string, "},");
printf("%d %d %s\r\n",
f_list[i].type,
f_list[i].size,
f_list[i].path
//tbuffer,
//ent->d_name
);
}
strcat(json_string, "{\"file\":\"");
strcat(json_string, f_list[files].path);
strcat(json_string, "\",\"size\":");
strcat(json_string, f_list[files].size);
strcat(json_string, "}]\0");
*/
printf(json_string);
//char *sarylosk = "{\"name\":\"sarylosk\"}";
httpd_resp_set_type(req, "application/json");
httpd_resp_send(req, json_string, strlen(json_string));
free(f_list);
free(json_string);
return ESP_OK;
}