Skip to content

Commit e3fcb9b

Browse files
committed
Introducing MAX_FILE_NAME_SIZE constant.
1 parent 40b8c03 commit e3fcb9b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/util/file_util.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ std::string concat_dir_file(
161161
/// This is not designed to operate on path names and will replace folder
162162
/// seperator characters.
163163
/// \param file_name: The file name to sanitize.
164-
std::string make_valid_filename(std::string file_name)
164+
/// \param max_size: The maximum size for the file name. If the name is longer,
165+
/// then its size will be cut to the max_size.
166+
std::string make_valid_filename(
167+
std::string file_name,
168+
const std::size_t max_size)
165169
{
166170
std::replace(file_name.begin(), file_name.end(), '#', '_');
167171
std::replace(file_name.begin(), file_name.end(), '$', '_');
@@ -170,5 +174,7 @@ std::string make_valid_filename(std::string file_name)
170174
std::replace(file_name.begin(), file_name.end(), '\\', '.');
171175
std::replace(file_name.begin(), file_name.end(), '<', '[');
172176
std::replace(file_name.begin(), file_name.end(), '>', ']');
177+
if(file_name.size() > max_size)
178+
file_name.resize(max_size);
173179
return file_name;
174180
}

src/util/file_util.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include <string>
1414

15+
/// This constant defines a maximum name length of any file created by
16+
/// any module of the CProver. The value of the constant was inferred
17+
/// from the most restrictive file system we use on our workstations:
18+
/// 'ecryptfs'.
19+
const std::size_t MAX_FILE_NAME_SIZE = 140;
20+
1521
void delete_directory(const std::string &path);
1622

1723
std::string get_current_working_directory();
1824

1925
std::string concat_dir_file(const std::string &directory,
2026
const std::string &file_name);
2127

22-
std::string make_valid_filename(std::string filename);
28+
std::string make_valid_filename(
29+
std::string filename,
30+
const std::size_t max_size = MAX_FILE_NAME_SIZE);
2331

2432
#endif // CPROVER_UTIL_FILE_UTIL_H

0 commit comments

Comments
 (0)