Skip to content

Commit 0040232

Browse files
committed
fix: some warning followed by clang-tidy
1 parent f56cea3 commit 0040232

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

include/snapshot/snapshot.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class StringUtility {
141141

142142
static std::vector<std::string> Split(const std::string& s, const char delimiter) {
143143
std::vector<std::string> res;
144-
int len = s.length();
144+
int len = static_cast<int>(s.length());
145145

146146
std::string t = "";
147147
for (int i = 0; i <= len; i++) {
@@ -184,7 +184,7 @@ class StringUtility {
184184
const char* escape_character_set = "\\\"\'\?\a\b\f\n\r\t\v\0";
185185

186186
const auto check = [&escape_character_set](char c) -> bool {
187-
auto p = escape_character_set;
187+
const auto* p = escape_character_set;
188188
while (*p) {
189189
if (c == *p) {
190190
return true;
@@ -246,7 +246,7 @@ class FileUtility {
246246

247247
while (true) {
248248
size_t cur_pos = path.find('/', pos + 1);
249-
pos = cur_pos;
249+
pos = static_cast<int>(cur_pos);
250250

251251
if (cur_pos == std::string::npos) {
252252
break;
@@ -296,14 +296,14 @@ class FileUtility {
296296
static void RewriteFile(const std::string& file_path, const std::string& content) {
297297
std::ofstream file;
298298
file.open(file_path, std::ofstream::out | std::ofstream::trunc);
299-
file.write(content.c_str(), content.length());
299+
file.write(content.c_str(), static_cast<long>(content.length()));
300300
file.close();
301301
}
302302

303303
static void AppendFile(const std::string& file_path, const std::string& content) {
304304
std::ofstream file;
305305
file.open(file_path, std::ofstream::out | std::ofstream::ate | std::ofstream::app);
306-
file.write(content.c_str(), content.length());
306+
file.write(content.c_str(), static_cast<long>(content.length()));
307307
file.close();
308308
}
309309

@@ -322,13 +322,13 @@ class FileUtility {
322322
int r = -1;
323323

324324
if (d) {
325-
struct dirent* p;
325+
struct dirent* p = nullptr;
326326

327327
r = 0;
328328
while (!r && (p = readdir(d))) {
329329
int r2 = -1;
330-
char* buf;
331-
size_t len;
330+
char* buf = nullptr;
331+
size_t len = 0;
332332

333333
/* Skip the names "." and ".." as we don't want to recurse on them. */
334334
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) {
@@ -431,7 +431,7 @@ class Snapshot {
431431
static T GenerateSnapshotInline(const T& t, const char* file_name, const int line_number) {
432432
const auto content = StringUtility::ToString(t);
433433
auto file_content = FileUtility::GetAllLines(file_name);
434-
auto& line_number_vec = getLineNumberVec(file_name, file_content.size());
434+
auto& line_number_vec = getLineNumberVec(file_name, static_cast<int>(file_content.size()));
435435
const auto actual_line_number = getActualLineNumber(line_number_vec, line_number);
436436

437437
auto match_range = getSnapshotInlineMatchRange(file_content[actual_line_number - 1]);
@@ -505,10 +505,10 @@ class Snapshot {
505505
static std::pair<int, int> getSnapshotInlineMatchRange(const std::string& s) {
506506
const std::string prefix = "SNAPSHOT_INLINE(";
507507

508-
int len = s.length();
509-
int prefix_len = prefix.length();
508+
int len = static_cast<int>(s.length());
509+
int prefix_len = static_cast<int>(prefix.length());
510510

511-
for (int i = prefix.length() - 1; i + 1 < len; i++) {
511+
for (int i = static_cast<int>(prefix.length()) - 1; i + 1 < len; i++) {
512512
if (s.substr(i - prefix_len + 1, prefix_len) == prefix) {
513513
int l = 1;
514514
for (int j = i + 1; j < len; j++) {

0 commit comments

Comments
 (0)