Skip to content

Commit

Permalink
Remove redundant duplicate strnlen call
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed Sep 23, 2024
1 parent cd55a2e commit 9280394
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions proto/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,14 @@ static int _transfer_single_file(int version, socket_t *socket, const char *file
}
}

const size_t _tmp_len = strnlen(tmp_fname, MAX_FILE_NAME_LENGTH);
if (_tmp_len > MAX_FILE_NAME_LENGTH) {
error("Too long file name.");
return EXIT_FAILURE;
}
char filename[_tmp_len + 1];
strncpy(filename, tmp_fname, _tmp_len);
filename[_tmp_len] = 0;
const size_t fname_len = strnlen(filename, _tmp_len);
if (fname_len <= 0 || fname_len > MIN(_tmp_len, MAX_FILE_NAME_LENGTH)) {
const size_t fname_len = strnlen(tmp_fname, MAX_FILE_NAME_LENGTH);
if (fname_len <= 0 || fname_len > MAX_FILE_NAME_LENGTH) {
error("Invalid file name length.");
return EXIT_FAILURE;
}
char filename[fname_len + 1];
strncpy(filename, tmp_fname, fname_len);
filename[fname_len] = 0;

#if PATH_SEP != '/'
if (version > 1) {
Expand Down

0 comments on commit 9280394

Please sign in to comment.