Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit d58a109

Browse files
committed
windows: fix size_t<->int conversions in ninja.exe
1 parent d98ba72 commit d58a109

10 files changed

+23
-23
lines changed

src/build_log.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const int kCurrentVersion = 5;
4949
#define BIG_CONSTANT(x) (x##LLU)
5050
#endif // !defined(_MSC_VER)
5151
inline
52-
uint64_t MurmurHash64A(const void* key, int len) {
52+
uint64_t MurmurHash64A(const void* key, size_t len) {
5353
static const uint64_t seed = 0xDECAFBADDECAFBADull;
5454
const uint64_t m = BIG_CONSTANT(0xc6a4a7935bd1e995);
5555
const int r = 47;
@@ -58,11 +58,11 @@ uint64_t MurmurHash64A(const void* key, int len) {
5858
const uint64_t * end = data + (len/8);
5959
while(data != end) {
6060
uint64_t k = *data++;
61-
k *= m;
62-
k ^= k >> r;
63-
k *= m;
61+
k *= m;
62+
k ^= k >> r;
63+
k *= m;
6464
h ^= k;
65-
h *= m;
65+
h *= m;
6666
}
6767
const unsigned char* data2 = (const unsigned char*)data;
6868
switch(len & 7)
@@ -80,7 +80,7 @@ uint64_t MurmurHash64A(const void* key, int len) {
8080
h *= m;
8181
h ^= h >> r;
8282
return h;
83-
}
83+
}
8484
#undef BIG_CONSTANT
8585

8686

src/depfile_parser.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bool DepfileParser::Parse(string* content, string* err) {
149149
yy5:
150150
{
151151
// Got a span of plain text.
152-
int len = in - start;
152+
int len = (int)(in - start);
153153
// Need to shift it over if we're overwriting backslashes.
154154
if (out < start)
155155
memmove(out, start, len);
@@ -191,7 +191,7 @@ bool DepfileParser::Parse(string* content, string* err) {
191191

192192
}
193193

194-
int len = out - filename;
194+
int len = (int)(out - filename);
195195
const bool is_target = parsing_targets;
196196
if (len > 0 && filename[len - 1] == ':') {
197197
len--; // Strip off trailing colon, if any.

src/depfile_parser.in.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool DepfileParser::Parse(string* content, string* err) {
7070
}
7171
[a-zA-Z0-9+,/_:.~()@=-]+ {
7272
// Got a span of plain text.
73-
int len = in - start;
73+
int len = (int)(in - start);
7474
// Need to shift it over if we're overwriting backslashes.
7575
if (out < start)
7676
memmove(out, start, len);
@@ -88,7 +88,7 @@ bool DepfileParser::Parse(string* content, string* err) {
8888
*/
8989
}
9090

91-
int len = out - filename;
91+
int len = (int)(out - filename);
9292
const bool is_target = parsing_targets;
9393
if (len > 0 && filename[len - 1] == ':') {
9494
len--; // Strip off trailing colon, if any.

src/graph.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ struct Edge {
199199
// pointer...)
200200
int implicit_deps_;
201201
int order_only_deps_;
202-
bool is_implicit(int index) {
203-
return index >= ((int)inputs_.size()) - order_only_deps_ - implicit_deps_ &&
202+
bool is_implicit(size_t index) {
203+
return index >= inputs_.size() - order_only_deps_ - implicit_deps_ &&
204204
!is_order_only(index);
205205
}
206-
bool is_order_only(int index) {
207-
return index >= ((int)inputs_.size()) - order_only_deps_;
206+
bool is_order_only(size_t index) {
207+
return index >= inputs_.size() - order_only_deps_;
208208
}
209209

210210
bool is_phony() const;

src/hash_map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// MurmurHash2, by Austin Appleby
2121
static inline
22-
unsigned int MurmurHash2(const void* key, int len) {
22+
unsigned int MurmurHash2(const void* key, size_t len) {
2323
static const unsigned int seed = 0xDECAFBAD;
2424
const unsigned int m = 0x5bd1e995;
2525
const int r = 24;

src/lexer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool Lexer::Error(const string& message, string* err) {
3030
context = p + 1;
3131
}
3232
}
33-
int col = last_token_ ? last_token_ - context : 0;
33+
int col = last_token_ ? (int)(last_token_ - context) : 0;
3434

3535
char buf[1024];
3636
snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line);

src/lexer.in.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool Lexer::Error(const string& message, string* err) {
2929
context = p + 1;
3030
}
3131
}
32-
int col = last_token_ ? last_token_ - context : 0;
32+
int col = last_token_ ? (int)(last_token_ - context) : 0;
3333

3434
char buf[1024];
3535
snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line);

src/string_piece.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct StringPiece {
3131
StringPiece(const string& str) : str_(str.data()), len_(str.size()) {}
3232
StringPiece(const char* str) : str_(str), len_(strlen(str)) {}
3333

34-
StringPiece(const char* str, int len) : str_(str), len_(len) {}
34+
StringPiece(const char* str, size_t len) : str_(str), len_(len) {}
3535

3636
bool operator==(const StringPiece& other) const {
3737
return len_ == other.len_ && memcmp(str_, other.str_, len_) == 0;
@@ -47,7 +47,7 @@ struct StringPiece {
4747
}
4848

4949
const char* str_;
50-
int len_;
50+
size_t len_;
5151
};
5252

5353
#endif // NINJA_STRINGPIECE_H_

src/util.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void Error(const char* msg, ...) {
8181

8282
bool CanonicalizePath(string* path, string* err) {
8383
METRIC_RECORD("canonicalize str");
84-
int len = path->size();
84+
size_t len = path->size();
8585
char* str = 0;
8686
if (len > 0)
8787
str = &(*path)[0];
@@ -91,7 +91,7 @@ bool CanonicalizePath(string* path, string* err) {
9191
return true;
9292
}
9393

94-
bool CanonicalizePath(char* path, int* len, string* err) {
94+
bool CanonicalizePath(char* path, size_t* len, string* err) {
9595
// WARNING: this function is performance-critical; please benchmark
9696
// any changes you make to it.
9797
METRIC_RECORD("canonicalize path");
@@ -323,7 +323,7 @@ string ElideMiddle(const string& str, size_t width) {
323323
const int kMargin = 3; // Space for "...".
324324
string result = str;
325325
if (result.size() + kMargin > width) {
326-
int elide_size = (width - kMargin) / 2;
326+
size_t elide_size = (width - kMargin) / 2;
327327
result = result.substr(0, elide_size)
328328
+ "..."
329329
+ result.substr(result.size() - elide_size, elide_size);

src/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void Error(const char* msg, ...);
3939
/// Canonicalize a path like "foo/../bar.h" into just "bar.h".
4040
bool CanonicalizePath(string* path, string* err);
4141

42-
bool CanonicalizePath(char* path, int* len, string* err);
42+
bool CanonicalizePath(char* path, size_t* len, string* err);
4343

4444
/// Read a file to a string.
4545
/// Returns -errno and fills in \a err on error.

0 commit comments

Comments
 (0)