Code: Select all
../components/webserver/webserver.c:57:5: error: 'strncpy' output truncated before terminating nul copying 8 bytes from a string of the same length [-Werror=stringop-truncation]
strncpy(filename, filepath_prefix, strlen(filepath_prefix));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code: Select all
const char *filepath_prefix = "/sdcard/www/";
char *filename = NULL;
size_t filename_len = httpd_req_get_url_query_len(req);
if (filename_len == 0) {
const char * resp_str = "Please specify a filename. eg. file?somefile.txt";
httpd_resp_send(req, resp_str, strlen(resp_str));
return ESP_OK;
}
filename = malloc(strlen(filepath_prefix) + filename_len + 1); // extra 1 byte for null termination
strncpy(filename, filepath_prefix, strlen(filepath_prefix));