aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-03-16 16:05:28 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-03-16 17:31:58 +0100
commit2c6fcae14552ab6e7addc82516617a135f86b5ca (patch)
treee6c8aff7b0fca5ef81c02bfb7c2d71ec6fc97046
parentabfae2b6d73d7be40ffbff8e8429f71d82df90b5 (diff)
cmake: improves error detection
Add detection of problem of cast. The problems are corrected in the patch. Change-Id: I8dc1e987531790860e390dea53ddf49d52339cb2 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/afm-db.c9
-rw-r--r--src/afm-launch.c29
-rw-r--r--src/afm-run.c2
-rw-r--r--src/utils-dir.c9
-rw-r--r--src/utils-dir.h5
-rw-r--r--src/utils-jbus.c11
-rw-r--r--src/wgt-config.c6
-rw-r--r--src/wgt-info.c4
-rw-r--r--src/wgt.c18
-rw-r--r--src/wgt.h2
-rw-r--r--src/wgtpkg-base64.c48
-rw-r--r--src/wgtpkg-base64.h6
-rw-r--r--src/wgtpkg-certs.c18
-rw-r--r--src/wgtpkg-digsig.c5
-rw-r--r--src/wgtpkg-digsig.h2
-rw-r--r--src/wgtpkg-files.c7
-rw-r--r--src/wgtpkg-install.c18
-rw-r--r--src/wgtpkg-permissions.c19
-rw-r--r--src/wgtpkg-uninstall.c8
-rw-r--r--src/wgtpkg-workdir.c11
-rw-r--r--src/wgtpkg-xmlsec.c4
-rw-r--r--src/wgtpkg-xmlsec.h2
-rw-r--r--src/wgtpkg-zip.c25
24 files changed, 153 insertions, 124 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 809d586..8971edb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -55,11 +55,14 @@ endif(USE_SIMULATION)
###########################################################################
-add_compile_options(-Wall -Wno-pointer-sign)
-add_compile_options(-Werror=maybe-uninitialized -Werror=implicit-function-declaration)
+add_compile_options(-Wall -Wextra -Wconversion)
+add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
+add_compile_options(-Werror=maybe-uninitialized)
+add_compile_options(-Werror=implicit-function-declaration)
+add_compile_options(-Wno-pointer-sign) # for XmlChar handling
add_compile_options(-ffunction-sections -fdata-sections)
-add_compile_options(-fPIC)
add_compile_options(-Wl,--gc-sections)
+add_compile_options(-fPIC)
set(CMAKE_C_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
diff --git a/src/afm-db.c b/src/afm-db.c
index 4dc2d5f..a903be0 100644
--- a/src/afm-db.c
+++ b/src/afm-db.c
@@ -254,7 +254,8 @@ static int enumentries(struct enumdata *data, int (*callto)(struct enumdata *))
errno = ENAMETOOLONG;
return -1;
}
- data->length = stpcpy(beg, entry.d_name) - data->path;
+ data->length = (int)(stpcpy(beg, entry.d_name)
+ - data->path);
/* call the function */
rc = callto(data);
if (rc)
@@ -430,9 +431,9 @@ int afm_db_update_applications(struct afm_db *afdb)
/* for each directory of afdb */
for (dir = afdb->dirhead ; dir != NULL ; dir = dir->next) {
if (dir->type == type_root) {
- edata.length = stpcpy(edata.path, dir->path)
- - edata.path;
- assert(edata.length < sizeof edata.path);
+ edata.length = (int)(stpcpy(edata.path, dir->path)
+ - edata.path);
+ assert(edata.length < (int)sizeof edata.path);
/* enumerate the applications */
rc = enumentries(&edata, enumvers);
if (rc)
diff --git a/src/afm-launch.c b/src/afm-launch.c
index 13f2bf9..87c5b12 100644
--- a/src/afm-launch.c
+++ b/src/afm-launch.c
@@ -141,8 +141,8 @@ static void dump_launchers(FILE *file)
static int next_token(struct confread *cread)
{
int idx = cread->index + cread->length;
- cread->index = idx + strspn(&cread->buffer[idx], separators);
- cread->length = strcspn(&cread->buffer[cread->index], separators);
+ cread->index = idx + (int)strspn(&cread->buffer[idx], separators);
+ cread->length = (int)strcspn(&cread->buffer[cread->index], separators);
return cread->length;
}
@@ -156,11 +156,11 @@ static int read_line(struct confread *cread)
{
while (fgets(cread->buffer, sizeof cread->buffer, cread->file) != NULL) {
cread->lineno++;
- cread->index = strspn(cread->buffer, separators);
+ cread->index = (int)strspn(cread->buffer, separators);
if (cread->buffer[cread->index]
&& cread->buffer[cread->index] != '#') {
- cread->length = strcspn(&cread->buffer[cread->index],
- separators);
+ cread->length = (int)strcspn(
+ &cread->buffer[cread->index], separators);
assert(cread->length > 0);
return cread->length;
}
@@ -183,7 +183,7 @@ static const char **read_vector(struct confread *cread)
int index0, length0;
const char **vector;
char *args;
- int count, length;
+ unsigned count, length;
/* record origin */
index0 = cread->index;
@@ -194,7 +194,7 @@ static const char **read_vector(struct confread *cread)
length = 0;
while(cread->length) {
count++;
- length += cread->length;
+ length += (unsigned)cread->length;
next_token(cread);
}
@@ -210,7 +210,8 @@ static const char **read_vector(struct confread *cread)
count = 0;
while(cread->length) {
vector[count++] = args;
- memcpy(args, &cread->buffer[cread->index], cread->length);
+ memcpy(args, &cread->buffer[cread->index],
+ (unsigned)cread->length);
args += cread->length;
*args++ = 0;
next_token(cread);
@@ -247,7 +248,7 @@ static struct type_list *read_type(struct confread *cread)
}
/* allocate structure */
- result = malloc(sizeof(struct type_list) + length);
+ result = malloc(sizeof(struct type_list) + (unsigned)length);
if (result == NULL) {
ERROR("%s:%d: out of memory", cread->filepath, cread->lineno);
errno = ENOMEM;
@@ -255,7 +256,7 @@ static struct type_list *read_type(struct confread *cread)
}
/* fill the structure */
- memcpy(result->type, &cread->buffer[index], length);
+ memcpy(result->type, &cread->buffer[index], (unsigned)length);
result->type[length] = 0;
return result;
}
@@ -531,7 +532,7 @@ static union arguments instantiate_arguments(
const char * const *iter;
const char *p, *v;
char *data, c, sep;
- int n, s;
+ unsigned n, s;
union arguments result;
char port[20], width[20], height[20], readyfd[20], mini[3];
@@ -615,7 +616,7 @@ static union arguments instantiate_arguments(
if (data)
data = stpcpy(data, v);
else
- s += strlen(v);
+ s += (unsigned)strlen(v);
}
}
/* terminate the argument */
@@ -891,7 +892,7 @@ int afm_launch(struct afm_launch_desc *desc, pid_t children[2], char **uri)
/* prepare paths */
rc = snprintf(datadir, sizeof datadir, "%s/%s",
desc->home, desc->appid);
- if (rc < 0 || rc >= sizeof datadir) {
+ if (rc < 0 || rc >= (int)sizeof datadir) {
ERROR("overflow for datadir");
errno = EINVAL;
return -1;
@@ -931,7 +932,7 @@ int afm_launch_initialize()
if (s && s != e)
groupid = s; /* the original groupid is used */
else
- groupid = -1;
+ groupid = (gid_t)-1;
rc = read_configuration_file(FWK_LAUNCH_CONF);
/* dump_launchers(stderr); */
diff --git a/src/afm-run.c b/src/afm-run.c
index 91e2a0b..152b57f 100644
--- a/src/afm-run.c
+++ b/src/afm-run.c
@@ -634,7 +634,7 @@ int afm_run_init()
}
rc = snprintf(dir, sizeof dir, "%s/%s", passwd.pw_dir,
fwk_user_app_dir);
- if (rc >= sizeof dir) {
+ if (rc >= (int)sizeof dir) {
ERROR("buffer overflow in user_app_dir for uid=%d",(int)me);
return -1;
}
diff --git a/src/utils-dir.c b/src/utils-dir.c
index 31bfd8a..96e803b 100644
--- a/src/utils-dir.c
+++ b/src/utils-dir.c
@@ -114,9 +114,10 @@ int remove_directory_at(int dirfd, const char *directory, int force)
}
/* create a directory */
-int create_directory_at(int dirfd, const char *directory, int mode, int mkparents)
+int create_directory_at(int dirfd, const char *directory, mode_t mode, int mkparents)
{
- int rc, len, l;
+ int rc;
+ size_t len, l;
char *copy;
const char *iter;
@@ -126,7 +127,7 @@ int create_directory_at(int dirfd, const char *directory, int mode, int mkparent
/* check parent of dest */
iter = strrchr(directory, '/');
- len = iter ? iter - directory : 0;
+ len = iter ? (size_t)(iter - directory) : 0;
if (!len)
return rc;
copy = strndupa(directory, len);
@@ -157,7 +158,7 @@ int create_directory_at(int dirfd, const char *directory, int mode, int mkparent
return mkdirat(dirfd, directory, mode);
}
-int create_directory(const char *directory, int mode, int mkparents)
+int create_directory(const char *directory, mode_t mode, int mkparents)
{
return create_directory_at(AT_FDCWD, directory, mode, mkparents);
}
diff --git a/src/utils-dir.h b/src/utils-dir.h
index 08736c3..cbeae1b 100644
--- a/src/utils-dir.h
+++ b/src/utils-dir.h
@@ -16,12 +16,13 @@
limitations under the License.
*/
+#include <sys/types.h>
int remove_directory_content_fd(int dirfd);
int remove_directory_content(const char *directory);
int remove_directory_content_at(int dirfd, const char *directory);
int remove_directory(const char *directory, int force);
int remove_directory_at(int dirfd, const char *directory, int force);
-int create_directory_at(int dirfd, const char *directory, int mode, int mkparents);
-int create_directory(const char *directory, int mode, int mkparents);
+int create_directory_at(int dirfd, const char *directory, mode_t mode, int mkparents);
+int create_directory(const char *directory, mode_t mode, int mkparents);
diff --git a/src/utils-jbus.c b/src/utils-jbus.c
index 6d01b1e..9d6c1d5 100644
--- a/src/utils-jbus.c
+++ b/src/utils-jbus.c
@@ -86,7 +86,7 @@ struct jbus {
char *name;
int watchnr;
int watchfd;
- int watchflags;
+ short watchflags;
};
/*********************** STATIC COMMON METHODS *****************/
@@ -407,12 +407,11 @@ static DBusHandlerResult incoming(DBusConnection *connection, DBusMessage *messa
static void watchset(DBusWatch *watch, struct jbus *jbus)
{
unsigned int flags;
- int wf, e;
+ short wf;
flags = dbus_watch_get_flags(watch);
- e = dbus_watch_get_enabled(watch);
wf = jbus->watchflags;
- if (e) {
+ if (dbus_watch_get_enabled(watch)) {
if (flags & DBUS_WATCH_READABLE)
wf |= POLLIN;
if (flags & DBUS_WATCH_WRITABLE)
@@ -721,7 +720,7 @@ int jbus_read_write_dispatch_multiple(struct jbus **jbuses, int njbuses, int tom
errno = EINVAL;
return -1;
}
- fds = alloca(njbuses * sizeof * fds);
+ fds = alloca((unsigned)njbuses * sizeof * fds);
assert(fds != NULL);
r = jbus_dispatch_multiple(jbuses, njbuses, maxcount);
@@ -729,7 +728,7 @@ int jbus_read_write_dispatch_multiple(struct jbus **jbuses, int njbuses, int tom
return r;
n = jbus_fill_pollfds(jbuses, njbuses, fds);
for(;;) {
- s = poll(fds, n, toms);
+ s = poll(fds, (nfds_t)n, toms);
if (s >= 0)
break;
if (errno != EINTR)
diff --git a/src/wgt-config.c b/src/wgt-config.c
index 1fb61bc..5760177 100644
--- a/src/wgt-config.c
+++ b/src/wgt-config.c
@@ -73,10 +73,10 @@ static xmlNodePtr first(const char *type)
return next(xmlDocGetRootElement(configxml)->children, type);
}
-static int scorelang(xmlNodePtr node)
+static unsigned int scorelang(xmlNodePtr node)
{
char *lang = xmlNodeGetLang(node);
- int score = wgt_locales_score(configwgt, lang);
+ unsigned int score = wgt_locales_score(configwgt, lang);
xmlFree(lang);
return score;
}
@@ -84,7 +84,7 @@ static int scorelang(xmlNodePtr node)
static xmlNodePtr element_based_localisation(const char *type)
{
xmlNodePtr resu, elem;
- int sr, s;
+ unsigned int sr, s;
resu = first(type);
if (resu) {
diff --git a/src/wgt-info.c b/src/wgt-info.c
index 02a619b..976fc54 100644
--- a/src/wgt-info.c
+++ b/src/wgt-info.c
@@ -77,7 +77,7 @@ static xmlChar *optcontent(xmlNodePtr node)
static char *mkver(char *version)
{
- int lver;
+ unsigned int lver;
char c, *r;
if (version) {
c = version[lver = 0];
@@ -100,7 +100,7 @@ static char *mkver(char *version)
static char *mkidaver(char *id, char *ver)
{
- int lid, lver;
+ size_t lid, lver;
char *r;
if (id && ver) {
lid = strlen(id);
diff --git a/src/wgt.c b/src/wgt.c
index 391c361..94fe317 100644
--- a/src/wgt.c
+++ b/src/wgt.c
@@ -34,7 +34,7 @@
struct wgt {
int refcount;
int rootfd;
- int nrlocales;
+ unsigned int nrlocales;
char **locales;
};
@@ -262,16 +262,16 @@ int wgt_open_read(struct wgt *wgt, const char *filename)
* Adds if needed the locale 'locstr' of 'length'
* to the list of locales.
*/
-static int locadd(struct wgt *wgt, const char *locstr, int length)
+static int locadd(struct wgt *wgt, const char *locstr, size_t length)
{
- int i;
+ unsigned int i;
char *item, **ptr;
item = strndup(locstr, length);
if (item != NULL) {
/* normalize in lower case */
for (i = 0 ; item[i] ; i++)
- item[i] = tolower(item[i]);
+ item[i] = (char)tolower(item[i]);
/* search it (no duplication) */
for (i = 0 ; i < wgt->nrlocales ; i++)
@@ -323,7 +323,7 @@ int wgt_locales_add(struct wgt *wgt, const char *locstr)
next = stop + !!*stop;
/* iterate variant of languages in reverse order */
while (locstr != stop) {
- if (locadd(wgt, locstr, stop - locstr))
+ if (locadd(wgt, locstr, (size_t)(stop - locstr)))
return -1;
do { stop--; } while(stop > locstr && *stop != '-');
}
@@ -338,9 +338,9 @@ int wgt_locales_add(struct wgt *wgt, const char *locstr)
* The lower result means the higher priority of the language.
* The returned value of 0 is the top first priority.
*/
-int wgt_locales_score(struct wgt *wgt, const char *lang)
+unsigned int wgt_locales_score(struct wgt *wgt, const char *lang)
{
- int i;
+ unsigned int i;
assert(wgt);
if (lang)
@@ -348,7 +348,7 @@ int wgt_locales_score(struct wgt *wgt, const char *lang)
if (!strcasecmp(lang, wgt->locales[i]))
return i;
- return INT_MAX;
+ return UINT_MAX;
}
/*
@@ -361,7 +361,7 @@ int wgt_locales_score(struct wgt *wgt, const char *lang)
*/
static const char *localize(struct wgt *wgt, const char *filename, char path[PATH_MAX])
{
- int i;
+ unsigned int i;
/* get the normalized name */
filename = normalsubpath(filename);
diff --git a/src/wgt.h b/src/wgt.h
index 82ad4db..0ac66f8 100644
--- a/src/wgt.h
+++ b/src/wgt.h
@@ -33,7 +33,7 @@ extern int wgt_is_connected(struct wgt *wgt);
/* management of locales */
extern void wgt_locales_reset(struct wgt *wgt);
extern int wgt_locales_add(struct wgt *wgt, const char *locstr);
-extern int wgt_locales_score(struct wgt *wgt, const char *lang);
+extern unsigned int wgt_locales_score(struct wgt *wgt, const char *lang);
/* direct access to files */
extern int wgt_has(struct wgt *wgt, const char *filename);
diff --git a/src/wgtpkg-base64.c b/src/wgtpkg-base64.c
index 63929ae..de9d282 100644
--- a/src/wgtpkg-base64.c
+++ b/src/wgtpkg-base64.c
@@ -26,20 +26,20 @@
static char tob64(char x)
{
if (x < 26)
- return 'A' + x;
+ return (char)('A' + x);
if (x < 52)
- return 'a' + x - 26;
+ return (char)('a' + x - 26);
if (x < 62)
- return '0' + x - 52;
+ return (char)('0' + x - 52);
return x == 62 ? '+' : '/';
}
-char *base64encw(const char *buffer, int length, int width)
+char *base64encw(const char *buffer, size_t length, unsigned width)
{
- int remain, in, out;
+ size_t remain, in, out;
char *result;
- if (width == 0 || width % 4) {
+ if (width == 0 || (width & 3) != 0) {
ERROR("bad width in base64enc");
return NULL;
}
@@ -54,8 +54,10 @@ char *base64encw(const char *buffer, int length, int width)
if (out % (width + 1) == width)
result[out++] = '\n';
result[out] = tob64((buffer[in] >> 2) & '\x3f');
- result[out+1] = tob64(((buffer[in] << 4) & '\x30') | ((buffer[in+1] >> 4) & '\x0f'));
- result[out+2] = tob64(((buffer[in+1] << 2) & '\x3c') | ((buffer[in+2] >> 6) & '\x03'));
+ result[out+1] = tob64((char)(((buffer[in] << 4) & '\x30')
+ | ((buffer[in+1] >> 4) & '\x0f')));
+ result[out+2] = tob64((char)(((buffer[in+1] << 2) & '\x3c')
+ | ((buffer[in+2] >> 6) & '\x03')));
result[out+3] = tob64(buffer[in+2] & '\x3f');
remain -= 3;
in += 3;
@@ -69,7 +71,8 @@ char *base64encw(const char *buffer, int length, int width)
result[out+1] = tob64((buffer[in] << 4) & '\x30');
result[out+2] = '=';
} else {
- result[out+1] = tob64(((buffer[in] << 4) & '\x30') | ((buffer[in+1] >> 4) & '\x0f'));
+ result[out+1] = tob64((char)(((buffer[in] << 4) & '\x30')
+ | ((buffer[in+1] >> 4) & '\x0f')));
result[out+2] = tob64((buffer[in+1] << 2) & '\x3c');
}
result[out+3] = '=';
@@ -79,7 +82,7 @@ char *base64encw(const char *buffer, int length, int width)
return result;
}
-char *base64enc(const char *buffer, int length)
+char *base64enc(const char *buffer, size_t length)
{
return base64encw(buffer, length, 76);
}
@@ -87,23 +90,24 @@ char *base64enc(const char *buffer, int length)
static char fromb64(char x)
{
if ('A' <= x && x <= 'Z')
- return x - 'A';
+ return (char)(x - 'A');
if ('a' <= x && x <= 'z')
- return x - 'a' + 26;
+ return (char)(x - 'a' + 26);
if ('0' <= x && x <= '9')
- return x - '0' + 52;
+ return (char)(x - '0' + 52);
if (x == '+')
- return 62;
+ return (char)62;
if (x == '/')
- return 63;
+ return (char)63;
if (x == '=')
return '@';
return 'E';
}
-int base64dec(const char *buffer, char **output)
+ssize_t base64dec(const char *buffer, char **output)
{
- int len, in, out;
+ size_t len, in;
+ ssize_t out;
char *result;
unsigned char x0, x1, x2, x3;
@@ -113,7 +117,8 @@ int base64dec(const char *buffer, char **output)
ERROR("malloc failed in base64dec");
return -1;
}
- in = out = 0;
+ in = 0;
+ out = 0;
while (buffer[in] == '\r' || buffer[in] == '\n')
in++;
while (buffer[in]) {
@@ -145,12 +150,17 @@ int base64dec(const char *buffer, char **output)
if (x3 != '@')
out += 3;
else if (!buffer[in])
- out += 1 + (x2 != '@');
+ out += 1 + (unsigned)(x2 != '@');
else {
ERROR("unexpected continuation in base64dec");
free(result);
return -1;
}
+ if (out < 0) {
+ ERROR("output too big in base64dec");
+ free(result);
+ return -1;
+ }
}
*output = result;
return out;
diff --git a/src/wgtpkg-base64.h b/src/wgtpkg-base64.h
index 90917a9..b3616b4 100644
--- a/src/wgtpkg-base64.h
+++ b/src/wgtpkg-base64.h
@@ -17,8 +17,8 @@
*/
-extern char *base64encw(const char *buffer, int length, int width);
-extern char *base64enc(const char *buffer, int length);
-extern int base64dec(const char *buffer, char **output);
+extern char *base64encw(const char *buffer, size_t length, unsigned width);
+extern char *base64enc(const char *buffer, size_t length);
+extern ssize_t base64dec(const char *buffer, char **output);
extern int base64eq(const char *buf1, const char *buf2);
diff --git a/src/wgtpkg-certs.c b/src/wgtpkg-certs.c
index 7310035..2201632 100644
--- a/src/wgtpkg-certs.c
+++ b/src/wgtpkg-certs.c
@@ -24,7 +24,7 @@
#include "wgtpkg-base64.h"
struct x509l {
- int count;
+ unsigned count;
X509 **certs;
};
@@ -32,7 +32,8 @@ static struct x509l certificates = { .count = 0, .certs = NULL };
static int add_certificate_x509(X509 *x)
{
- X509 **p = realloc(certificates.certs, (certificates.count + 1) * sizeof(X509*));
+ X509 **p = realloc(certificates.certs,
+ (certificates.count + 1) * sizeof(X509*));
if (!p) {
ERROR("reallocation failed for certificate");
return -1;
@@ -42,7 +43,7 @@ static int add_certificate_x509(X509 *x)
return 0;
}
-static int add_certificate_bin(const char *bin, int len)
+static int add_certificate_bin(const char *bin, size_t len)
{
int rc;
const char *b, *e;
@@ -66,12 +67,15 @@ static int add_certificate_bin(const char *bin, int len)
int add_certificate_b64(const char *b64)
{
char *d;
- int l = base64dec(b64, &d);
- if (l > 0) {
- l = add_certificate_bin(d, l);
+ ssize_t l = base64dec(b64, &d);
+ int rc;
+ if (l < 0)
+ rc = -1;
+ else {
+ rc = add_certificate_bin(d, (size_t)l);
free(d);
}
- return l;
+ return rc;
}
void clear_certificates()
diff --git a/src/wgtpkg-digsig.c b/src/wgtpkg-digsig.c
index ed9d089..baccbed 100644
--- a/src/wgtpkg-digsig.c
+++ b/src/wgtpkg-digsig.c
@@ -357,11 +357,12 @@ int check_all_signatures()
/* create a signature of 'index' (0 for author, other values for distributors)
using the private 'key' (filename) and the certificates 'certs' (filenames)
as trusted chain */
-int create_digsig(int index, const char *key, const char **certs)
+int create_digsig(unsigned int index, const char *key, const char **certs)
{
struct filedesc *fdesc;
xmlDocPtr doc;
- int rc, len, fd;
+ int rc, fd;
+ long len;
xmlSaveCtxtPtr ctx;
rc = -1;
diff --git a/src/wgtpkg-digsig.h b/src/wgtpkg-digsig.h
index 99c5a56..ad0788a 100644
--- a/src/wgtpkg-digsig.h
+++ b/src/wgtpkg-digsig.h
@@ -21,7 +21,7 @@
extern int verify_digsig(struct filedesc *fdesc);
/* create a digital signature */
-extern int create_digsig(int index, const char *key, const char **certs);
+extern int create_digsig(unsigned int index, const char *key, const char **certs);
/* check the signatures of the current directory */
extern int check_all_signatures();
diff --git a/src/wgtpkg-files.c b/src/wgtpkg-files.c
index cbd6048..46ea047 100644
--- a/src/wgtpkg-files.c
+++ b/src/wgtpkg-files.c
@@ -252,9 +252,10 @@ void file_clear_flags()
allfiles.files[i]->flags &= flag_signature;
}
-static int fill_files_rec(char name[PATH_MAX], int offset)
+static int fill_files_rec(char name[PATH_MAX], unsigned offset)
{
- int len, err, fd;
+ int err, fd;
+ unsigned len;
DIR *dir;
struct dirent *ent;
@@ -274,7 +275,7 @@ static int fill_files_rec(char name[PATH_MAX], int offset)
ent = readdir(dir);
while (ent != NULL) {
- len = strlen(ent->d_name);
+ len = (unsigned)strlen(ent->d_name);
if (ent->d_name[0] == '.' && (len == 1 ||
(ent->d_name[1] == '.' && len == 2)))
;
diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c
index deb2741..264606a 100644
--- a/src/wgtpkg-install.c
+++ b/src/wgtpkg-install.c
@@ -121,7 +121,7 @@ static int move_widget(const char *root, const struct wgt_desc *desc, int force)
int rc;
rc = snprintf(newdir, sizeof newdir, "%s/%s/%s", root, desc->id, desc->ver);
- if (rc >= sizeof newdir) {
+ if (rc >= (int)sizeof newdir) {
ERROR("path to long in move_widget");
errno = EINVAL;
return -1;
@@ -138,14 +138,14 @@ static int install_icon(const struct wgt_desc *desc)
create_directory(FWK_ICON_DIR, 0755, 1);
rc = snprintf(link, sizeof link, "%s/%s", FWK_ICON_DIR, desc->idaver);
- if (rc >= sizeof link) {
+ if (rc >= (int)sizeof link) {
ERROR("link to long in install_icon");
errno = EINVAL;
return -1;
}
rc = snprintf(target, sizeof target, "%s/%s", workdir, desc->icons->src);
- if (rc >= sizeof target) {
+ if (rc >= (int)sizeof target) {
ERROR("target to long in install_icon");
errno = EINVAL;
return -1;
@@ -162,8 +162,8 @@ static int install_security(const struct wgt_desc *desc)
{
char path[PATH_MAX], *head;
const char *icon, *perm;
- int rc, len, lic, lf;
- unsigned int i, n;
+ int rc;
+ unsigned int i, n, len, lic, lf;
struct filedesc *f;
rc = secmgr_init(desc->id);
@@ -176,8 +176,8 @@ static int install_security(const struct wgt_desc *desc)
/* instal the files */
head = stpcpy(path, workdir);
- assert(sizeof path > (head - path));
- len = (int)(sizeof path - (head - path));
+ assert(head < path + sizeof path);
+ len = (unsigned)((path + sizeof path) - head);
if (!len) {
ERROR("root path too long in install_security");
errno = ENAMETOOLONG;
@@ -186,12 +186,12 @@ static int install_security(const struct wgt_desc *desc)
len--;
*head++ = '/';
icon = desc->icons->src;
- lic = (int)strlen(icon);
+ lic = (unsigned)strlen(icon);
n = file_count();
i = 0;
while(i < n) {
f = file_of_index(i++);
- lf = (int)strlen(f->name);
+ lf = (unsigned)strlen(f->name);
if (lf >= len) {
ERROR("path too long in install_security");
errno = ENAMETOOLONG;
diff --git a/src/wgtpkg-permissions.c b/src/wgtpkg-permissions.c
index 88bce05..9e061c8 100644
--- a/src/wgtpkg-permissions.c
+++ b/src/wgtpkg-permissions.c
@@ -34,9 +34,9 @@ struct permission {
static const char prefix_of_permissions[] = FWK_PREFIX_PERMISSION;
-static int nrpermissions = 0;
+static unsigned int nrpermissions = 0;
static struct permission *permissions = NULL;
-static int indexiter = 0;
+static unsigned int indexiter = 0;
/* check is the name has the correct prefix for permissions */
int is_standard_permission(const char *name)
@@ -47,7 +47,7 @@ int is_standard_permission(const char *name)
/* retrieves the permission of name */
static struct permission *get_permission(const char *name)
{
- int i;
+ unsigned int i;
for (i = 0 ; i < nrpermissions ; i++)
if (0 == strcmp(permissions[i].name, name))
@@ -60,7 +60,8 @@ static struct permission *add_permission(const char *name)
{
struct permission *p = get_permission(name);
if (!p) {
- p = realloc(permissions, ((nrpermissions + 8) & ~7) * sizeof(*p));
+ p = realloc(permissions,
+ ((nrpermissions + 8) & ~(unsigned)7) * sizeof(*p));
if (p) {
permissions = p;
p = permissions + nrpermissions;
@@ -68,6 +69,8 @@ static struct permission *add_permission(const char *name)
p->name = strdup(name);
if (!p->name)
p = NULL;
+ else
+ nrpermissions++;
}
}
return p;
@@ -76,7 +79,7 @@ static struct permission *add_permission(const char *name)
/* remove any granting */
void reset_permissions()
{
- int i;
+ unsigned int i;
for (i = 0 ; i < nrpermissions ; i++)
permissions[i].granted = 0;
}
@@ -84,7 +87,7 @@ void reset_permissions()
/* remove any granting */
void crop_permissions(unsigned level)
{
- int i;
+ unsigned int i;
for (i = 0 ; i < nrpermissions ; i++)
if (permissions[i].level < level)
permissions[i].granted = 0;
@@ -95,13 +98,13 @@ void grant_permission_list(const char *list)
{
struct permission *p;
char *iter, c;
- int n;
+ unsigned int n;
static const char separators[] = " \t\n\r,";
iter = strdupa(list);
iter += strspn(iter, separators);
while(*iter) {
- n = strcspn(iter, separators);
+ n = (unsigned)strcspn(iter, separators);
c = iter[n];
iter[n] = 0;
p = add_permission(iter);
diff --git a/src/wgtpkg-uninstall.c b/src/wgtpkg-uninstall.c
index 7516c3f..1d4e0df 100644
--- a/src/wgtpkg-uninstall.c
+++ b/src/wgtpkg-uninstall.c
@@ -47,12 +47,12 @@ int uninstall_widget(const char *idaver, const char *root)
errno = EINVAL;
return -1;
}
- id = strndupa(idaver, at - idaver);
+ id = strndupa(idaver, (size_t)(at - idaver));
ver = strdupa(at + 1);
/* compute the path */
rc = snprintf(path, sizeof path, "%s/%s/%s", root, id, ver);
- if (rc >= sizeof path) {
+ if (rc >= (int)sizeof path) {
ERROR("bad widget id '%s', too long", idaver);
errno = EINVAL;
return -1;
@@ -67,14 +67,14 @@ int uninstall_widget(const char *idaver, const char *root)
/* removes the icon of the application */
rc = snprintf(path, sizeof path, "%s/%s", FWK_ICON_DIR, idaver);
- assert(rc < sizeof path);
+ assert(rc < (int)sizeof path);
rc = unlink(path);
if (rc < 0)
ERROR("can't removing '%s': %m", path);
/* removes the parent directory if empty */
rc2 = snprintf(path, sizeof path, "%s/%s", root, id);
- assert(rc2 < sizeof path);
+ assert(rc2 < (int)sizeof path);
rc2 = rmdir(path);
if (rc < 0 && errno == ENOTEMPTY)
return rc;
diff --git a/src/wgtpkg-workdir.c b/src/wgtpkg-workdir.c
index 342df48..7d6e2a8 100644
--- a/src/wgtpkg-workdir.c
+++ b/src/wgtpkg-workdir.c
@@ -34,7 +34,7 @@
#include "wgtpkg-workdir.h"
#include "utils-dir.h"
-static const int dirmode = 0755;
+static const mode_t dirmode = 0755;
char workdir[PATH_MAX] = { 0, };
int workdirfd = -1;
@@ -116,7 +116,7 @@ int make_workdir(const char *root, const char *prefix, int reuse)
put_workdir(AT_FDCWD, ".", 1);
n = snprintf(workdir, sizeof workdir, "%s/%s", root, prefix);
- if (n >= sizeof workdir) {
+ if (n >= (int)sizeof workdir) {
ERROR("workdir prefix too long");
errno = EINVAL;
return -1;
@@ -129,7 +129,7 @@ int make_workdir(const char *root, const char *prefix, int reuse)
ERROR("exhaustion of workdirs");
return -1;
}
- l = snprintf(workdir + n, r, "%d", i);
+ l = snprintf(workdir + n, (unsigned)r, "%d", i);
if (l >= r) {
ERROR("computed workdir too long");
errno = EINVAL;
@@ -156,7 +156,8 @@ int make_workdir(const char *root, const char *prefix, int reuse)
int move_workdir(const char *dest, int parents, int force)
{
- int rc, len;
+ int rc;
+ size_t len;
struct stat s;
char *copy;
const char *iter;
@@ -194,7 +195,7 @@ int move_workdir(const char *dest, int parents, int force)
} else {
/* check parent of dest */
iter = strrchr(dest, '/');
- len = iter ? iter - dest : 0;
+ len = iter ? (size_t)(iter - dest) : 0;
if (len) {
/* is parent existing? */
copy = strndupa(dest, len);
diff --git a/src/wgtpkg-xmlsec.c b/src/wgtpkg-xmlsec.c
index 2d52cc6..f2863db 100644
--- a/src/wgtpkg-xmlsec.c
+++ b/src/wgtpkg-xmlsec.c
@@ -80,7 +80,7 @@ static void *file_open_cb(const char *file)
/* read the opened file */
static int file_read_cb(void *context, char *buffer, int len)
{
- size_t r = fread(buffer, 1, len, (FILE*)context);
+ size_t r = fread(buffer, 1, (unsigned)len, (FILE*)context);
return r ? (int)r : feof((FILE*)context) ? 0 : - 1;
}
@@ -274,7 +274,7 @@ static const struct { const char *id; const char *xml; } properties[2] = {
/* create a signature of 'index' (0 for author, other values for distributors)
using the private 'key' (filename) and the certificates 'certs' (filenames)
as trusted chain */
-xmlDocPtr xmlsec_create(int index, const char *key, const char **certs)
+xmlDocPtr xmlsec_create(unsigned int index, const char *key, const char **certs)
{
unsigned int i, fc, mask;
struct filedesc *fdesc;
diff --git a/src/wgtpkg-xmlsec.h b/src/wgtpkg-xmlsec.h
index 92d7615..08597ab 100644
--- a/src/wgtpkg-xmlsec.h
+++ b/src/wgtpkg-xmlsec.h
@@ -19,5 +19,5 @@
extern int xmlsec_init();
extern void xmlsec_shutdown();
extern int xmlsec_verify(xmlNodePtr node);
-extern xmlDocPtr xmlsec_create(int index, const char *key, const char **certs);
+extern xmlDocPtr xmlsec_create(unsigned int index, const char *key, const char **certs);
diff --git a/src/wgtpkg-zip.c b/src/wgtpkg-zip.c
index caae1c9..aba0520 100644
--- a/src/wgtpkg-zip.c
+++ b/src/wgtpkg-zip.c
@@ -68,7 +68,7 @@ static int is_valid_filename(const char *filename)
return !lastsp;
}
-static int create_directory(char *file, int mode)
+static int create_directory(char *file, mode_t mode)
{
int rc;
char *last = strrchr(file, '/');
@@ -91,7 +91,7 @@ static int create_directory(char *file, int mode)
return rc;
}
-static int create_file(char *file, int fmode, int dmode)
+static int create_file(char *file, int fmode, mode_t dmode)
{
int fd = openat(workdirfd, file, O_CREAT|O_WRONLY|O_TRUNC, fmode);
if (fd < 0 && errno == ENOENT) {
@@ -107,9 +107,11 @@ static int create_file(char *file, int fmode, int dmode)
int zread(const char *zipfile, unsigned long long maxsize)
{
struct filedesc *fdesc;
- int err, fd, len;
+ int err, fd;
+ size_t len;
struct zip *zip;
zip_int64_t z64;
+ zip_uint64_t uz64;
unsigned int count, index;
struct zip_file *zfile;
struct zip_stat zstat;
@@ -195,19 +197,19 @@ int zread(const char *zipfile, unsigned long long maxsize)
if (fd < 0)
goto errorz;
/* extract */
- z64 = zstat.size;
- while (z64) {
+ uz64 = zstat.size;
+ while (uz64) {
sizr = zip_fread(zfile, buffer, sizeof buffer);
if (sizr < 0) {
ERROR("error while reading %s in %s", zstat.name, zipfile);
goto errorzf;
}
- sizw = write(fd, buffer, sizr);
+ sizw = write(fd, buffer, (size_t)sizr);
if (sizw < 0) {
ERROR("error while writing %s", zstat.name);
goto errorzf;
}
- z64 -= sizw;
+ uz64 -= (size_t)sizw;
}
close(fd);
zip_fclose(zfile);
@@ -232,9 +234,10 @@ struct zws {
char buffer[32768];
};
-static int zwr(struct zws *zws, int offset)
+static int zwr(struct zws *zws, size_t offset)
{
- int len, err, fd;
+ int err, fd;
+ size_t len;
DIR *dir;
struct dirent *ent;
zip_int64_t z64;
@@ -243,13 +246,13 @@ static int zwr(struct zws *zws, int offset)
fd = openat(workdirfd, offset ? zws->name : ".", O_DIRECTORY|O_RDONLY);
if (fd < 0) {
- ERROR("opendir %.*s failed in zwr", offset, zws->name);
+ ERROR("opendir %.*s failed in zwr", (int)offset, zws->name);
return -1;
}
dir = fdopendir(fd);
if (!dir) {
close(fd);
- ERROR("opendir %.*s failed in zwr", offset, zws->name);
+ ERROR("opendir %.*s failed in zwr", (int)offset, zws->name);
return -1;
}