Fix some random -Wconversion warnings

This commit is contained in:
Eelco Dolstra 2018-05-02 13:56:34 +02:00
parent 548ad391d9
commit 53ec5ac69f
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
16 changed files with 82 additions and 80 deletions

View file

@ -24,13 +24,15 @@ static void * allocBytes(size_t n)
/* Allocate a new array of attributes for an attribute set with a specific /* Allocate a new array of attributes for an attribute set with a specific
capacity. The space is implicitly reserved after the Bindings capacity. The space is implicitly reserved after the Bindings
structure. */ structure. */
Bindings * EvalState::allocBindings(Bindings::size_t capacity) Bindings * EvalState::allocBindings(size_t capacity)
{ {
return new (allocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings(capacity); if (capacity > std::numeric_limits<Bindings::size_t>::max())
throw Error("attribute set of size %d is too big", capacity);
return new (allocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings((Bindings::size_t) capacity);
} }
void EvalState::mkAttrs(Value & v, unsigned int capacity) void EvalState::mkAttrs(Value & v, size_t capacity)
{ {
if (capacity == 0) { if (capacity == 0) {
v = vEmptySet; v = vEmptySet;

View file

@ -422,7 +422,7 @@ Value * EvalState::addConstant(const string & name, Value & v)
Value * EvalState::addPrimOp(const string & name, Value * EvalState::addPrimOp(const string & name,
unsigned int arity, PrimOpFun primOp) size_t arity, PrimOpFun primOp)
{ {
if (arity == 0) { if (arity == 0) {
Value v; Value v;
@ -528,7 +528,7 @@ Value & mkString(Value & v, const string & s, const PathSet & context)
{ {
mkString(v, s.c_str()); mkString(v, s.c_str());
if (!context.empty()) { if (!context.empty()) {
unsigned int n = 0; size_t n = 0;
v.string.context = (const char * *) v.string.context = (const char * *)
allocBytes((context.size() + 1) * sizeof(char *)); allocBytes((context.size() + 1) * sizeof(char *));
for (auto & i : context) for (auto & i : context)
@ -547,7 +547,7 @@ void mkPath(Value & v, const char * s)
inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval) inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
{ {
for (unsigned int l = var.level; l; --l, env = env->up) ; for (size_t l = var.level; l; --l, env = env->up) ;
if (!var.fromWith) return env->values[var.displ]; if (!var.fromWith) return env->values[var.displ];
@ -566,7 +566,7 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
} }
if (!env->prevWith) if (!env->prevWith)
throwUndefinedVarError("undefined variable '%1%' at %2%", var.name, var.pos); throwUndefinedVarError("undefined variable '%1%' at %2%", var.name, var.pos);
for (unsigned int l = env->prevWith; l; --l, env = env->up) ; for (size_t l = env->prevWith; l; --l, env = env->up) ;
} }
} }
@ -578,14 +578,15 @@ Value * EvalState::allocValue()
} }
Env & EvalState::allocEnv(unsigned int size) Env & EvalState::allocEnv(size_t size)
{ {
assert(size <= std::numeric_limits<decltype(Env::size)>::max()); if (size > std::numeric_limits<decltype(Env::size)>::max())
throw Error("environment size %d is too big", size);
nrEnvs++; nrEnvs++;
nrValuesInEnvs += size; nrValuesInEnvs += size;
Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *)); Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
env->size = size; env->size = (decltype(Env::size)) size;
/* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */ /* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */
@ -593,7 +594,7 @@ Env & EvalState::allocEnv(unsigned int size)
} }
void EvalState::mkList(Value & v, unsigned int size) void EvalState::mkList(Value & v, size_t size)
{ {
clearValue(v); clearValue(v);
if (size == 1) if (size == 1)
@ -805,7 +806,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
/* The recursive attributes are evaluated in the new /* The recursive attributes are evaluated in the new
environment, while the inherited attributes are evaluated environment, while the inherited attributes are evaluated
in the original environment. */ in the original environment. */
unsigned int displ = 0; size_t displ = 0;
for (auto & i : attrs) { for (auto & i : attrs) {
Value * vAttr; Value * vAttr;
if (hasOverrides && !i.second.inherited) { if (hasOverrides && !i.second.inherited) {
@ -879,7 +880,7 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
/* The recursive attributes are evaluated in the new environment, /* The recursive attributes are evaluated in the new environment,
while the inherited attributes are evaluated in the original while the inherited attributes are evaluated in the original
environment. */ environment. */
unsigned int displ = 0; size_t displ = 0;
for (auto & i : attrs->attrs) for (auto & i : attrs->attrs)
env2.values[displ++] = i.second.e->maybeThunk(state, i.second.inherited ? env : env2); env2.values[displ++] = i.second.e->maybeThunk(state, i.second.inherited ? env : env2);
@ -890,7 +891,7 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
void ExprList::eval(EvalState & state, Env & env, Value & v) void ExprList::eval(EvalState & state, Env & env, Value & v)
{ {
state.mkList(v, elems.size()); state.mkList(v, elems.size());
for (unsigned int n = 0; n < elems.size(); ++n) for (size_t n = 0; n < elems.size(); ++n)
v.listElems()[n] = elems[n]->maybeThunk(state, env); v.listElems()[n] = elems[n]->maybeThunk(state, env);
} }
@ -1012,22 +1013,22 @@ void ExprApp::eval(EvalState & state, Env & env, Value & v)
void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos) void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos)
{ {
/* Figure out the number of arguments still needed. */ /* Figure out the number of arguments still needed. */
unsigned int argsDone = 0; size_t argsDone = 0;
Value * primOp = &fun; Value * primOp = &fun;
while (primOp->type == tPrimOpApp) { while (primOp->type == tPrimOpApp) {
argsDone++; argsDone++;
primOp = primOp->primOpApp.left; primOp = primOp->primOpApp.left;
} }
assert(primOp->type == tPrimOp); assert(primOp->type == tPrimOp);
unsigned int arity = primOp->primOp->arity; auto arity = primOp->primOp->arity;
unsigned int argsLeft = arity - argsDone; auto argsLeft = arity - argsDone;
if (argsLeft == 1) { if (argsLeft == 1) {
/* We have all the arguments, so call the primop. */ /* We have all the arguments, so call the primop. */
/* Put all the arguments in an array. */ /* Put all the arguments in an array. */
Value * vArgs[arity]; Value * vArgs[arity];
unsigned int n = arity - 1; auto n = arity - 1;
vArgs[n--] = &arg; vArgs[n--] = &arg;
for (Value * arg = &fun; arg->type == tPrimOpApp; arg = arg->primOpApp.left) for (Value * arg = &fun; arg->type == tPrimOpApp; arg = arg->primOpApp.left)
vArgs[n--] = arg->primOpApp.right; vArgs[n--] = arg->primOpApp.right;
@ -1076,13 +1077,13 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
ExprLambda & lambda(*fun.lambda.fun); ExprLambda & lambda(*fun.lambda.fun);
unsigned int size = auto size =
(lambda.arg.empty() ? 0 : 1) + (lambda.arg.empty() ? 0 : 1) +
(lambda.matchAttrs ? lambda.formals->formals.size() : 0); (lambda.matchAttrs ? lambda.formals->formals.size() : 0);
Env & env2(allocEnv(size)); Env & env2(allocEnv(size));
env2.up = fun.lambda.env; env2.up = fun.lambda.env;
unsigned int displ = 0; size_t displ = 0;
if (!lambda.matchAttrs) if (!lambda.matchAttrs)
env2.values[displ++] = &arg; env2.values[displ++] = &arg;
@ -1096,7 +1097,7 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
/* For each formal argument, get the actual argument. If /* For each formal argument, get the actual argument. If
there is no matching actual argument but the formal there is no matching actual argument but the formal
argument has a default, use the default. */ argument has a default, use the default. */
unsigned int attrsUsed = 0; size_t attrsUsed = 0;
for (auto & i : lambda.formals->formals) { for (auto & i : lambda.formals->formals) {
Bindings::iterator j = arg.attrs->find(i.name); Bindings::iterator j = arg.attrs->find(i.name);
if (j == arg.attrs->end()) { if (j == arg.attrs->end()) {
@ -1294,15 +1295,15 @@ void ExprOpConcatLists::eval(EvalState & state, Env & env, Value & v)
} }
void EvalState::concatLists(Value & v, unsigned int nrLists, Value * * lists, const Pos & pos) void EvalState::concatLists(Value & v, size_t nrLists, Value * * lists, const Pos & pos)
{ {
nrListConcats++; nrListConcats++;
Value * nonEmpty = 0; Value * nonEmpty = 0;
unsigned int len = 0; size_t len = 0;
for (unsigned int n = 0; n < nrLists; ++n) { for (size_t n = 0; n < nrLists; ++n) {
forceList(*lists[n], pos); forceList(*lists[n], pos);
unsigned int l = lists[n]->listSize(); auto l = lists[n]->listSize();
len += l; len += l;
if (l) nonEmpty = lists[n]; if (l) nonEmpty = lists[n];
} }
@ -1314,8 +1315,8 @@ void EvalState::concatLists(Value & v, unsigned int nrLists, Value * * lists, co
mkList(v, len); mkList(v, len);
auto out = v.listElems(); auto out = v.listElems();
for (unsigned int n = 0, pos = 0; n < nrLists; ++n) { for (size_t n = 0, pos = 0; n < nrLists; ++n) {
unsigned int l = lists[n]->listSize(); auto l = lists[n]->listSize();
if (l) if (l)
memcpy(out + pos, lists[n]->listElems(), l * sizeof(Value *)); memcpy(out + pos, lists[n]->listElems(), l * sizeof(Value *));
pos += l; pos += l;
@ -1410,7 +1411,7 @@ void EvalState::forceValueDeep(Value & v)
} }
else if (v.isList()) { else if (v.isList()) {
for (unsigned int n = 0; n < v.listSize(); ++n) for (size_t n = 0; n < v.listSize(); ++n)
recurse(*v.listElems()[n]); recurse(*v.listElems()[n]);
} }
}; };
@ -1562,7 +1563,7 @@ string EvalState::coerceToString(const Pos & pos, Value & v, PathSet & context,
if (v.isList()) { if (v.isList()) {
string result; string result;
for (unsigned int n = 0; n < v.listSize(); ++n) { for (size_t n = 0; n < v.listSize(); ++n) {
result += coerceToString(pos, *v.listElems()[n], result += coerceToString(pos, *v.listElems()[n],
context, coerceMore, copyToStore); context, coerceMore, copyToStore);
if (n < v.listSize() - 1 if (n < v.listSize() - 1
@ -1649,7 +1650,7 @@ bool EvalState::eqValues(Value & v1, Value & v2)
case tList2: case tList2:
case tListN: case tListN:
if (v1.listSize() != v2.listSize()) return false; if (v1.listSize() != v2.listSize()) return false;
for (unsigned int n = 0; n < v1.listSize(); ++n) for (size_t n = 0; n < v1.listSize(); ++n)
if (!eqValues(*v1.listElems()[n], *v2.listElems()[n])) return false; if (!eqValues(*v1.listElems()[n], *v2.listElems()[n])) return false;
return true; return true;
@ -1740,26 +1741,26 @@ void EvalState::printStats()
v = lvlInfo; v = lvlInfo;
printMsg(v, format("calls to %1% primops:") % primOpCalls.size()); printMsg(v, format("calls to %1% primops:") % primOpCalls.size());
typedef std::multimap<unsigned int, Symbol> PrimOpCalls_; typedef std::multimap<size_t, Symbol> PrimOpCalls_;
PrimOpCalls_ primOpCalls_; PrimOpCalls_ primOpCalls_;
for (auto & i : primOpCalls) for (auto & i : primOpCalls)
primOpCalls_.insert(std::pair<unsigned int, Symbol>(i.second, i.first)); primOpCalls_.insert(std::pair<size_t, Symbol>(i.second, i.first));
for (auto i = primOpCalls_.rbegin(); i != primOpCalls_.rend(); ++i) for (auto i = primOpCalls_.rbegin(); i != primOpCalls_.rend(); ++i)
printMsg(v, format("%1$10d %2%") % i->first % i->second); printMsg(v, format("%1$10d %2%") % i->first % i->second);
printMsg(v, format("calls to %1% functions:") % functionCalls.size()); printMsg(v, format("calls to %1% functions:") % functionCalls.size());
typedef std::multimap<unsigned int, ExprLambda *> FunctionCalls_; typedef std::multimap<size_t, ExprLambda *> FunctionCalls_;
FunctionCalls_ functionCalls_; FunctionCalls_ functionCalls_;
for (auto & i : functionCalls) for (auto & i : functionCalls)
functionCalls_.insert(std::pair<unsigned int, ExprLambda *>(i.second, i.first)); functionCalls_.insert(std::pair<size_t, ExprLambda *>(i.second, i.first));
for (auto i = functionCalls_.rbegin(); i != functionCalls_.rend(); ++i) for (auto i = functionCalls_.rbegin(); i != functionCalls_.rend(); ++i)
printMsg(v, format("%1$10d %2%") % i->first % i->second->showNamePos()); printMsg(v, format("%1$10d %2%") % i->first % i->second->showNamePos());
printMsg(v, format("evaluations of %1% attributes:") % attrSelects.size()); printMsg(v, format("evaluations of %1% attributes:") % attrSelects.size());
typedef std::multimap<unsigned int, Pos> AttrSelects_; typedef std::multimap<size_t, Pos> AttrSelects_;
AttrSelects_ attrSelects_; AttrSelects_ attrSelects_;
for (auto & i : attrSelects) for (auto & i : attrSelects)
attrSelects_.insert(std::pair<unsigned int, Pos>(i.second, i.first)); attrSelects_.insert(std::pair<size_t, Pos>(i.second, i.first));
for (auto i = attrSelects_.rbegin(); i != attrSelects_.rend(); ++i) for (auto i = attrSelects_.rbegin(); i != attrSelects_.rend(); ++i)
printMsg(v, format("%1$10d %2%") % i->first % i->second); printMsg(v, format("%1$10d %2%") % i->first % i->second);
@ -1810,7 +1811,7 @@ size_t valueSize(Value & v)
if (seen.find(v.listElems()) == seen.end()) { if (seen.find(v.listElems()) == seen.end()) {
seen.insert(v.listElems()); seen.insert(v.listElems());
sz += v.listSize() * sizeof(Value *); sz += v.listSize() * sizeof(Value *);
for (unsigned int n = 0; n < v.listSize(); ++n) for (size_t n = 0; n < v.listSize(); ++n)
sz += doValue(*v.listElems()[n]); sz += doValue(*v.listElems()[n]);
} }
break; break;
@ -1846,7 +1847,7 @@ size_t valueSize(Value & v)
size_t sz = sizeof(Env) + sizeof(Value *) * env.size; size_t sz = sizeof(Env) + sizeof(Value *) * env.size;
for (unsigned int i = 0; i < env.size; ++i) for (size_t i = 0; i < env.size; ++i)
if (env.values[i]) if (env.values[i])
sz += doValue(*env.values[i]); sz += doValue(*env.values[i]);

View file

@ -214,7 +214,7 @@ private:
Value * addConstant(const string & name, Value & v); Value * addConstant(const string & name, Value & v);
Value * addPrimOp(const string & name, Value * addPrimOp(const string & name,
unsigned int arity, PrimOpFun primOp); size_t arity, PrimOpFun primOp);
public: public:
@ -248,18 +248,18 @@ public:
/* Allocation primitives. */ /* Allocation primitives. */
Value * allocValue(); Value * allocValue();
Env & allocEnv(unsigned int size); Env & allocEnv(size_t size);
Value * allocAttr(Value & vAttrs, const Symbol & name); Value * allocAttr(Value & vAttrs, const Symbol & name);
Bindings * allocBindings(Bindings::size_t capacity); Bindings * allocBindings(size_t capacity);
void mkList(Value & v, unsigned int length); void mkList(Value & v, size_t length);
void mkAttrs(Value & v, unsigned int capacity); void mkAttrs(Value & v, size_t capacity);
void mkThunk_(Value & v, Expr * expr); void mkThunk_(Value & v, Expr * expr);
void mkPos(Value & v, Pos * pos); void mkPos(Value & v, Pos * pos);
void concatLists(Value & v, unsigned int nrLists, Value * * lists, const Pos & pos); void concatLists(Value & v, size_t nrLists, Value * * lists, const Pos & pos);
/* Print statistics. */ /* Print statistics. */
void printStats(); void printStats();
@ -282,15 +282,15 @@ private:
bool countCalls; bool countCalls;
typedef std::map<Symbol, unsigned int> PrimOpCalls; typedef std::map<Symbol, size_t> PrimOpCalls;
PrimOpCalls primOpCalls; PrimOpCalls primOpCalls;
typedef std::map<ExprLambda *, unsigned int> FunctionCalls; typedef std::map<ExprLambda *, size_t> FunctionCalls;
FunctionCalls functionCalls; FunctionCalls functionCalls;
void incrFunctionCall(ExprLambda * fun); void incrFunctionCall(ExprLambda * fun);
typedef std::map<Pos, unsigned int> AttrSelects; typedef std::map<Pos, size_t> AttrSelects;
AttrSelects attrSelects; AttrSelects attrSelects;
friend struct ExprOpUpdate; friend struct ExprOpUpdate;

View file

@ -255,7 +255,7 @@ struct ExprWith : Expr
{ {
Pos pos; Pos pos;
Expr * attrs, * body; Expr * attrs, * body;
unsigned int prevWith; size_t prevWith;
ExprWith(const Pos & pos, Expr * attrs, Expr * body) : pos(pos), attrs(attrs), body(body) { }; ExprWith(const Pos & pos, Expr * attrs, Expr * body) : pos(pos), attrs(attrs), body(body) { };
COMMON_METHODS COMMON_METHODS
}; };

View file

@ -136,8 +136,8 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
whitespace-only final lines are not taken into account. (So whitespace-only final lines are not taken into account. (So
the " " in "\n ''" is ignored, but the " " in "\n foo''" is.) */ the " " in "\n ''" is ignored, but the " " in "\n foo''" is.) */
bool atStartOfLine = true; /* = seen only whitespace in the current line */ bool atStartOfLine = true; /* = seen only whitespace in the current line */
unsigned int minIndent = 1000000; size_t minIndent = 1000000;
unsigned int curIndent = 0; size_t curIndent = 0;
for (auto & i : es) { for (auto & i : es) {
ExprIndStr * e = dynamic_cast<ExprIndStr *>(i); ExprIndStr * e = dynamic_cast<ExprIndStr *>(i);
if (!e) { if (!e) {
@ -148,7 +148,7 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
} }
continue; continue;
} }
for (unsigned int j = 0; j < e->s.size(); ++j) { for (size_t j = 0; j < e->s.size(); ++j) {
if (atStartOfLine) { if (atStartOfLine) {
if (e->s[j] == ' ') if (e->s[j] == ' ')
curIndent++; curIndent++;
@ -170,8 +170,8 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
/* Strip spaces from each line. */ /* Strip spaces from each line. */
vector<Expr *> * es2 = new vector<Expr *>; vector<Expr *> * es2 = new vector<Expr *>;
atStartOfLine = true; atStartOfLine = true;
unsigned int curDropped = 0; size_t curDropped = 0;
unsigned int n = es.size(); size_t n = es.size();
for (vector<Expr *>::iterator i = es.begin(); i != es.end(); ++i, --n) { for (vector<Expr *>::iterator i = es.begin(); i != es.end(); ++i, --n) {
ExprIndStr * e = dynamic_cast<ExprIndStr *>(*i); ExprIndStr * e = dynamic_cast<ExprIndStr *>(*i);
if (!e) { if (!e) {
@ -182,7 +182,7 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex
} }
string s2; string s2;
for (unsigned int j = 0; j < e->s.size(); ++j) { for (size_t j = 0; j < e->s.size(); ++j) {
if (atStartOfLine) { if (atStartOfLine) {
if (e->s[j] == ' ') { if (e->s[j] == ' ') {
if (curDropped++ >= minIndent) if (curDropped++ >= minIndent)

View file

@ -69,7 +69,7 @@ public:
return Symbol(&*res.first); return Symbol(&*res.first);
} }
unsigned int size() const size_t size() const
{ {
return symbols.size(); return symbols.size();
} }

View file

@ -128,7 +128,7 @@ struct Value
const char * path; const char * path;
Bindings * attrs; Bindings * attrs;
struct { struct {
unsigned int size; size_t size;
Value * * elems; Value * * elems;
} bigList; } bigList;
Value * smallList[2]; Value * smallList[2];
@ -166,7 +166,7 @@ struct Value
return type == tList1 || type == tList2 ? smallList : bigList.elems; return type == tList1 || type == tList2 ? smallList : bigList.elems;
} }
unsigned int listSize() const size_t listSize() const
{ {
return type == tList1 ? 1 : type == tList2 ? 2 : bigList.size; return type == tList1 ? 1 : type == tList2 ? 2 : bigList.size;
} }

View file

@ -30,7 +30,7 @@ static void sigsegvHandler(int signo, siginfo_t * info, void * ctx)
if (diff < 0) diff = -diff; if (diff < 0) diff = -diff;
if (diff < 4096) { if (diff < 4096) {
char msg[] = "error: stack overflow (possible infinite recursion)\n"; char msg[] = "error: stack overflow (possible infinite recursion)\n";
[[gnu::unused]] int res = write(2, msg, strlen(msg)); [[gnu::unused]] auto res = write(2, msg, strlen(msg));
_exit(1); // maybe abort instead? _exit(1); // maybe abort instead?
} }
} }

View file

@ -842,9 +842,9 @@ private:
BuildResult result; BuildResult result;
/* The current round, if we're building multiple times. */ /* The current round, if we're building multiple times. */
unsigned int curRound = 1; size_t curRound = 1;
unsigned int nrRounds; size_t nrRounds;
/* Path registration info from the previous round, if we're /* Path registration info from the previous round, if we're
building multiple times. Since this contains the hash, it building multiple times. Since this contains the hash, it
@ -1169,7 +1169,7 @@ void DerivationGoal::outputsSubstituted()
return; return;
} }
unsigned int nrInvalid = checkPathValidity(false, buildMode == bmRepair).size(); auto nrInvalid = checkPathValidity(false, buildMode == bmRepair).size();
if (buildMode == bmNormal && nrInvalid == 0) { if (buildMode == bmNormal && nrInvalid == 0) {
done(BuildResult::Substituted); done(BuildResult::Substituted);
return; return;

View file

@ -13,7 +13,7 @@ namespace nix {
static unsigned int refLength = 32; /* characters */ static unsigned int refLength = 32; /* characters */
static void search(const unsigned char * s, unsigned int len, static void search(const unsigned char * s, size_t len,
StringSet & hashes, StringSet & seen) StringSet & hashes, StringSet & seen)
{ {
static bool initialised = false; static bool initialised = false;
@ -25,7 +25,7 @@ static void search(const unsigned char * s, unsigned int len,
initialised = true; initialised = true;
} }
for (unsigned int i = 0; i + refLength <= len; ) { for (size_t i = 0; i + refLength <= len; ) {
int j; int j;
bool match = true; bool match = true;
for (j = refLength - 1; j >= 0; --j) for (j = refLength - 1; j >= 0; --j)
@ -73,7 +73,7 @@ void RefScanSink::operator () (const unsigned char * data, size_t len)
search(data, len, hashes, seen); search(data, len, hashes, seen);
unsigned int tailLen = len <= refLength ? len : refLength; size_t tailLen = len <= refLength ? len : refLength;
tail = tail =
string(tail, tail.size() < refLength - tailLen ? 0 : tail.size() - (refLength - tailLen)) + string(tail, tail.size() < refLength - tailLen ? 0 : tail.size() - (refLength - tailLen)) +
string((const char *) data + len - tailLen, tailLen); string((const char *) data + len - tailLen, tailLen);

View file

@ -82,7 +82,7 @@ static string printHash32(const Hash & hash)
string s; string s;
s.reserve(len); s.reserve(len);
for (int n = len - 1; n >= 0; n--) { for (int n = (int) len - 1; n >= 0; n--) {
unsigned int b = n * 5; unsigned int b = n * 5;
unsigned int i = b / 8; unsigned int i = b / 8;
unsigned int j = b % 8; unsigned int j = b % 8;

View file

@ -227,7 +227,7 @@ inline Sink & operator << (Sink & sink, uint64_t n)
buf[4] = (n >> 32) & 0xff; buf[4] = (n >> 32) & 0xff;
buf[5] = (n >> 40) & 0xff; buf[5] = (n >> 40) & 0xff;
buf[6] = (n >> 48) & 0xff; buf[6] = (n >> 48) & 0xff;
buf[7] = (n >> 56) & 0xff; buf[7] = (unsigned char) (n >> 56) & 0xff;
sink(buf, sizeof(buf)); sink(buf, sizeof(buf));
return sink; return sink;
} }
@ -259,7 +259,7 @@ T readNum(Source & source)
if (n > std::numeric_limits<T>::max()) if (n > std::numeric_limits<T>::max())
throw SerialisationError("serialised integer %d is too large for type '%s'", n, typeid(T).name()); throw SerialisationError("serialised integer %d is too large for type '%s'", n, typeid(T).name());
return n; return (T) n;
} }

View file

@ -28,7 +28,7 @@ void XMLWriter::close()
} }
void XMLWriter::indent_(unsigned int depth) void XMLWriter::indent_(size_t depth)
{ {
if (!indent) return; if (!indent) return;
output << string(depth * 2, ' '); output << string(depth * 2, ' ');
@ -75,7 +75,7 @@ void XMLWriter::writeAttrs(const XMLAttrs & attrs)
{ {
for (auto & i : attrs) { for (auto & i : attrs) {
output << " " << i.first << "=\""; output << " " << i.first << "=\"";
for (unsigned int j = 0; j < i.second.size(); ++j) { for (size_t j = 0; j < i.second.size(); ++j) {
char c = i.second[j]; char c = i.second[j];
if (c == '"') output << "&quot;"; if (c == '"') output << "&quot;";
else if (c == '<') output << "&lt;"; else if (c == '<') output << "&lt;";

View file

@ -44,7 +44,7 @@ public:
private: private:
void writeAttrs(const XMLAttrs & attrs); void writeAttrs(const XMLAttrs & attrs);
void indent_(unsigned int depth); void indent_(size_t depth);
}; };

View file

@ -198,13 +198,13 @@ static Path getDefNixExprPath()
} }
static int getPriority(EvalState & state, DrvInfo & drv) static long getPriority(EvalState & state, DrvInfo & drv)
{ {
return drv.queryMetaInt("priority", 0); return drv.queryMetaInt("priority", 0);
} }
static int comparePriorities(EvalState & state, DrvInfo & drv1, DrvInfo & drv2) static long comparePriorities(EvalState & state, DrvInfo & drv1, DrvInfo & drv2)
{ {
return getPriority(state, drv2) - getPriority(state, drv1); return getPriority(state, drv2) - getPriority(state, drv1);
} }
@ -270,7 +270,7 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems,
for (auto & j : matches) { for (auto & j : matches) {
DrvName drvName(j.first.queryName()); DrvName drvName(j.first.queryName());
int d = 1; long d = 1;
Newest::iterator k = newest.find(drvName.name); Newest::iterator k = newest.find(drvName.name);
@ -578,7 +578,7 @@ static void upgradeDerivations(Globals & globals,
(upgradeType == utEq && d == 0) || (upgradeType == utEq && d == 0) ||
upgradeType == utAlways) upgradeType == utAlways)
{ {
int d2 = -1; long d2 = -1;
if (bestElem != availElems.end()) { if (bestElem != availElems.end()) {
d2 = comparePriorities(*globals.state, *bestElem, *j); d2 = comparePriorities(*globals.state, *bestElem, *j);
if (d2 == 0) d2 = compareVersions(bestVersion, newName.version); if (d2 == 0) d2 = compareVersions(bestVersion, newName.version);
@ -784,22 +784,22 @@ typedef list<Strings> Table;
void printTable(Table & table) void printTable(Table & table)
{ {
unsigned int nrColumns = table.size() > 0 ? table.front().size() : 0; auto nrColumns = table.size() > 0 ? table.front().size() : 0;
vector<unsigned int> widths; vector<size_t> widths;
widths.resize(nrColumns); widths.resize(nrColumns);
for (auto & i : table) { for (auto & i : table) {
assert(i.size() == nrColumns); assert(i.size() == nrColumns);
Strings::iterator j; Strings::iterator j;
unsigned int column; size_t column;
for (j = i.begin(), column = 0; j != i.end(); ++j, ++column) for (j = i.begin(), column = 0; j != i.end(); ++j, ++column)
if (j->size() > widths[column]) widths[column] = j->size(); if (j->size() > widths[column]) widths[column] = j->size();
} }
for (auto & i : table) { for (auto & i : table) {
Strings::iterator j; Strings::iterator j;
unsigned int column; size_t column;
for (j = i.begin(), column = 0; j != i.end(); ++j, ++column) { for (j = i.begin(), column = 0; j != i.end(); ++j, ++column) {
string s = *j; string s = *j;
replace(s.begin(), s.end(), '\n', ' '); replace(s.begin(), s.end(), '\n', ' ');

View file

@ -47,8 +47,7 @@ static string makeNode(const string & id, const string & label,
static string symbolicName(const string & path) static string symbolicName(const string & path)
{ {
string p = baseNameOf(path); string p = baseNameOf(path);
int dash = p.find('-'); return string(p, p.find('-') + 1);
return string(p, dash + 1);
} }