Skip to content

Commit

Permalink
Resolved code review change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
s3gfaultx committed Jul 5, 2024
1 parent aefe528 commit 2d845d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
9 changes: 5 additions & 4 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -4588,6 +4588,7 @@ bool config_load_remap(const char *directory_input_remapping,
char *remap_path = NULL;
bool sort_remaps_by_controller = settings->bools.input_remap_sort_by_controller_enable;
size_t remap_path_total_len = 0;
size_t _len = 0;

content_dir_name[0] = '\0';
core_path[0] = '\0';
Expand All @@ -4605,16 +4606,16 @@ bool config_load_remap(const char *directory_input_remapping,
&& !string_is_empty(input_device_name))
{
/* Ensure directory does not contain special chars */
input_device_dir = sanitize_path_part(input_device_name);
input_device_dir = sanitize_path_part(input_device_name, strlen(input_device_name));

/* Allocate memory for the new path */
remap_path_total_len = strlen(core_name) + strlen(input_device_dir) + 2;
remap_path = (char *)malloc(remap_path_total_len);

/* Build the new path with the controller name */
strlcpy(remap_path, core_name, remap_path_total_len);
strlcat(remap_path, "/", remap_path_total_len);
strlcat(remap_path, input_device_dir, remap_path_total_len);
_len = strlcpy(remap_path, core_name, remap_path_total_len);
_len += strlcpy(remap_path + _len, "/", remap_path_total_len - _len);
_len += strlcpy(remap_path + _len, input_device_dir, remap_path_total_len - _len);

/* Deallocate as we no longer this */
free((char*)input_device_dir);
Expand Down
12 changes: 5 additions & 7 deletions libretro-common/file/file_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ size_t fill_pathname_abbreviate_special(char *out_path,
*
* @returns new string that has been sanitized
**/
const char *sanitize_path_part(const char *path_part)
const char *sanitize_path_part(const char *path_part, size_t size)
{
int i;
int j = 0;
Expand All @@ -1171,16 +1171,14 @@ const char *sanitize_path_part(const char *path_part)
if (string_is_empty(path_part))
return NULL;

len = strlen(path_part);
temp = (char *)malloc((len + 1) * sizeof(char));
temp = (char *)malloc((size + 1) * sizeof(char));

for (i = 0; path_part[i] != '\0'; i++) {
for (i = 0; path_part[i] != '\0'; i++)
/* Check if the current character is one of the special characters */
if (strchr(special_chars, path_part[i]) == NULL) {
if (strchr(special_chars, path_part[i]) == NULL)
/* If not, copy it to the temporary array */
temp[j++] = path_part[i];
}
}

temp[j] = '\0';

/* Return the new string */
Expand Down
7 changes: 4 additions & 3 deletions libretro-common/include/file/file_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,16 @@ size_t fill_pathname_abbreviated_or_relative(char *out_path,
/**
* sanitize_path_part:
*
* @path_part : directory or filename
*
* @path_part : directory or filename
* @size : length of path_part
*
* Takes single part of a path eg. single filename
* or directory, and removes any special chars that are
* unavailable.
*
* @returns new string that has been sanitized
**/
const char *sanitize_path_part(const char *path_part);
const char *sanitize_path_part(const char *path_part, size_t size);

/**
* pathname_conform_slashes_to_os:
Expand Down
9 changes: 5 additions & 4 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,7 @@ static int generic_action_ok_remap_file_operation(const char *path,
char *remap_path = NULL;
bool sort_remaps_by_controller = settings->bools.input_remap_sort_by_controller_enable;
size_t remap_path_total_len = 0;
size_t _len = 0;

content_dir_name[0] = '\0';
remap_file_path[0] = '\0';
Expand All @@ -3672,16 +3673,16 @@ static int generic_action_ok_remap_file_operation(const char *path,
&& !string_is_empty(input_device_name))
{
/* Ensure directory does not contain special chars */
input_device_dir = sanitize_path_part(input_device_name);
input_device_dir = sanitize_path_part(input_device_name, strlen(input_device_name));

/* Allocate memory for the new path */
remap_path_total_len = strlen(core_name) + strlen(input_device_dir) + 2;
remap_path = (char *)malloc(remap_path_total_len);

/* Build the new path with the controller name */
strlcpy(remap_path, core_name, remap_path_total_len);
strlcat(remap_path, "/", remap_path_total_len);
strlcat(remap_path, input_device_dir, remap_path_total_len);
_len = strlcpy(remap_path, core_name, remap_path_total_len);
_len += strlcat(remap_path + _len, "/", remap_path_total_len - _len);
_len += strlcat(remap_path + _len, input_device_dir, remap_path_total_len - _len);

/* Deallocate as we no longer this */
free((char*)input_device_dir);
Expand Down

0 comments on commit 2d845d5

Please sign in to comment.