From: Michael Schroeder Date: Fri, 29 Aug 2014 11:10:14 +0000 (+0200) Subject: get rid of a couple of warnings for msvc X-Git-Tag: 0.6.5~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c330d5cd4dc0eea93acf903884afc70297e1fd22;p=thirdparty%2Flibsolv.git get rid of a couple of warnings for msvc --- diff --git a/src/poolid.c b/src/poolid.c index 5fe502b4..7bcc1f60 100644 --- a/src/poolid.c +++ b/src/poolid.c @@ -65,7 +65,7 @@ pool_rel2id(Pool *pool, Id name, Id evr, int flags, int create) ran = pool->rels; /* extend hashtable if needed */ - if (pool->nrels * 2 > hashmask) + if ((Hashval)pool->nrels * 2 > hashmask) { solv_free(pool->relhashtbl); pool->relhashmask = hashmask = mkmask(pool->nrels + REL_BLOCK); diff --git a/src/qsort_r.c b/src/qsort_r.c index f264ed0a..d49049aa 100644 --- a/src/qsort_r.c +++ b/src/qsort_r.c @@ -47,7 +47,9 @@ typedef int cmp_t(const void *, const void *, void *); static inline char *med3(char *, char *, char *, cmp_t *, void *); static inline void swapfunc(char *, char *, int, int); +#ifndef min #define min(a, b) (a) < (b) ? a : b +#endif /* * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". diff --git a/src/repo.c b/src/repo.c index 511fd922..15e7e80d 100644 --- a/src/repo.c +++ b/src/repo.c @@ -388,10 +388,10 @@ repo_addid_dep_hash(Repo *repo, Offset olddeps, Id id, Id marker, int size) } /* maintain hash and lastmarkerpos */ - if (repo->lastidhash_idarraysize != repo->idarraysize || size * 2 > repo->lastidhash_mask || repo->lastmarker != marker) + if (repo->lastidhash_idarraysize != repo->idarraysize || (Hashval)size * 2 > repo->lastidhash_mask || repo->lastmarker != marker) { repo->lastmarkerpos = 0; - if (size * 2 > repo->lastidhash_mask) + if (size * 2 > (Hashval)repo->lastidhash_mask) { repo->lastidhash_mask = mkmask(size < REPO_ADDID_DEP_HASHMIN ? REPO_ADDID_DEP_HASHMIN : size); repo->lastidhash = solv_realloc2(repo->lastidhash, repo->lastidhash_mask + 1, sizeof(Id)); diff --git a/src/repo.h b/src/repo.h index 106f2a53..952dbeba 100644 --- a/src/repo.h +++ b/src/repo.h @@ -41,7 +41,7 @@ typedef struct _Repo { Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */ int idarraysize; - unsigned nrepodata; /* number of our stores.. */ + int nrepodata; /* number of our stores.. */ Id *rpmdbid; /* solvable side data: rpm database id */ diff --git a/src/repo_solv.c b/src/repo_solv.c index 0e8b8541..86c851cc 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -113,7 +113,7 @@ read_id(Repodata *data, Id max) if (!(c & 128)) { x = (x << 7) | c; - if (max && x >= max) + if (max && x >= (unsigned int)max) { data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "read_id: id too large (%u/%u)", x, max); return 0; @@ -149,7 +149,7 @@ read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end) continue; } x = (x << 6) | (c & 63); - if (max && x >= max) + if (max && x >= (unsigned int)max) { data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "read_idarray: id too large (%u/%u)", x, max); return 0; @@ -217,7 +217,7 @@ data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, Repodata *da continue; } x = (x << 6) | (c & 63); - if (max && x >= max) + if (max && x >= (unsigned int)max) { data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_idarray: id too large (%u/%u)", x, max); data->error = SOLV_ERROR_ID_RANGE; @@ -261,7 +261,7 @@ data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, Repodata } x = old + (x - 1); old = x; - if (max && x >= max) + if (max && x >= (unsigned int)max) { data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_rel_idarray: id too large (%u/%u)", x, max); break; @@ -360,7 +360,7 @@ incore_add_ideof(Repodata *data, Id sx, int eof) static void incore_add_blob(Repodata *data, unsigned char *buf, int len) { - if (data->incoredatafree < len) + if (data->incoredatafree < (unsigned int)len) { data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK + len); data->incoredatafree = INCORE_ADD_CHUNK + len; @@ -444,8 +444,8 @@ repo_add_solv(Repo *repo, FILE *fp, int flags) { Pool *pool = repo->pool; int i, l; - unsigned int numid, numrel, numdir, numsolv; - unsigned int numkeys, numschemata; + int numid, numrel, numdir, numsolv; + int numkeys, numschemata; Offset sizeid; Offset *str; /* map Id -> Offset into string space */ @@ -519,16 +519,26 @@ repo_add_solv(Repo *repo, FILE *fp, int flags) return pool_error(pool, SOLV_ERROR_UNSUPPORTED, "unsupported SOLV version"); } - numid = read_u32(&data); - numrel = read_u32(&data); - numdir = read_u32(&data); - numsolv = read_u32(&data); - numkeys = read_u32(&data); - numschemata = read_u32(&data); + numid = (int)read_u32(&data); + numrel = (int)read_u32(&data); + numdir = (int)read_u32(&data); + numsolv = (int)read_u32(&data); + numkeys = (int)read_u32(&data); + numschemata = (int)read_u32(&data); solvflags = read_u32(&data); - if (numdir && numdir < 2) + if (numid < 0 || numid >= 0x20000000) + return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of ids"); + if (numrel < 0 || numrel >= 0x20000000) + return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of rels"); + if (numdir && (numdir < 2 || numdir >= 0x20000000)) return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of dirs"); + if (numsolv < 0 || numsolv >= 0x20000000) + return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of solvables"); + if (numkeys < 0 || numkeys >= 0x20000000) + return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of keys"); + if (numschemata < 0 || numschemata >= 0x20000000) + return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of schematas"); if (numrel && (flags & REPO_LOCALPOOL) != 0) return pool_error(pool, SOLV_ERROR_CORRUPT, "relations are forbidden in a local pool"); diff --git a/src/repo_write.c b/src/repo_write.c index 11002b44..210636c4 100644 --- a/src/repo_write.c +++ b/src/repo_write.c @@ -1568,7 +1568,7 @@ for (i = 1; i < target.nkeys; i++) /* remove unused keys */ keyused = solv_calloc(target.nkeys, sizeof(Id)); - for (i = 1; i < target.schemadatalen; i++) + for (i = 1; i < (int)target.schemadatalen; i++) keyused[target.schemadata[i]] = 1; keyused[0] = 0; for (n = i = 1; i < target.nkeys; i++) @@ -1592,7 +1592,7 @@ for (i = 1; i < target.nkeys; i++) queue_truncate(keyq, 2 * n - 2); /* update schema data to the new key ids */ - for (i = 1; i < target.schemadatalen; i++) + for (i = 1; i < (int)target.schemadatalen; i++) target.schemadata[i] = keyused[target.schemadata[i]]; /* update keymap to the new key ids */ for (i = 0; i < cbdata.nkeymap; i++) diff --git a/src/repodata.c b/src/repodata.c index d527a421..4d577902 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -479,11 +479,11 @@ get_vertical_data(Repodata *data, Repokey *key, Id off, Id len) if (off >= data->lastverticaloffset) { off -= data->lastverticaloffset; - if (off + len > data->vincorelen) + if ((unsigned int)off + len > data->vincorelen) return 0; return data->vincore + off; } - if (off + len > key->size) + if ((unsigned int)off + len > key->size) return 0; /* we now have the offset, go into vertical */ off += data->verticaloffset[key - data->keys]; @@ -2928,7 +2928,7 @@ compact_attrdata(Repodata *data, int entry, int nentry) case REPOKEY_TYPE_STR: case REPOKEY_TYPE_BINARY: case_CHKSUM_TYPES: - if (attrs[1] < attrdatastart) + if ((unsigned int)attrs[1] < attrdatastart) attrdatastart = attrs[1]; break; case REPOKEY_TYPE_DIRSTRARRAY: @@ -2938,7 +2938,7 @@ compact_attrdata(Repodata *data, int entry, int nentry) /* FALLTHROUGH */ case REPOKEY_TYPE_IDARRAY: case REPOKEY_TYPE_DIRNUMNUMARRAY: - if (attrs[1] < attriddatastart) + if ((unsigned int)attrs[1] < attriddatastart) attriddatastart = attrs[1]; break; case REPOKEY_TYPE_FIXARRAY: diff --git a/src/strpool.c b/src/strpool.c index 3ad0a800..af43e01d 100644 --- a/src/strpool.c +++ b/src/strpool.c @@ -93,7 +93,7 @@ stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create hashtbl = ss->stringhashtbl; /* expand hashtable if needed */ - if (ss->nstrings * 2 > hashmask) + if ((Hashval)ss->nstrings * 2 > hashmask) { solv_free(hashtbl);