Remove some compilation warnings.

This commit is contained in:
Milan Broz
2012-06-10 18:56:04 +02:00
parent c364290be9
commit 4b8f91d0d9
6 changed files with 32 additions and 21 deletions

View File

@@ -77,7 +77,7 @@ ssize_t write_lseek_blockwise(int fd, char *buf, size_t count, off_t offset);
int device_ready(struct crypt_device *cd, const char *device, int mode); int device_ready(struct crypt_device *cd, const char *device, int mode);
int device_size(const char *device, uint64_t *size); int device_size(const char *device, uint64_t *size);
int crypt_getpagesize(void); unsigned crypt_getpagesize(void);
enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 }; enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 };
int device_check_and_adjust(struct crypt_device *cd, int device_check_and_adjust(struct crypt_device *cd,

View File

@@ -256,10 +256,10 @@ static void hex_key(char *hexkey, size_t key_size, const char *key)
sprintf(&hexkey[i * 2], "%02x", (unsigned char)key[i]); sprintf(&hexkey[i * 2], "%02x", (unsigned char)key[i]);
} }
static int hex_to_bytes(const char *hex, char *result) static size_t hex_to_bytes(const char *hex, char *result)
{ {
char buf[3] = "xx\0", *endp; char buf[3] = "xx\0", *endp;
int i, len; size_t i, len;
len = strlen(hex) / 2; len = strlen(hex) / 2;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {

View File

@@ -912,6 +912,9 @@ static int _crypt_format_plain(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
if (!(cd->type = strdup(CRYPT_PLAIN)))
return -ENOMEM;
cd->plain_key_size = volume_key_size; cd->plain_key_size = volume_key_size;
cd->volume_key = crypt_alloc_volume_key(volume_key_size, NULL); cd->volume_key = crypt_alloc_volume_key(volume_key_size, NULL);
if (!cd->volume_key) if (!cd->volume_key)
@@ -953,6 +956,9 @@ static int _crypt_format_luks1(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
if (!(cd->type = strdup(CRYPT_LUKS1)))
return -ENOMEM;
if (volume_key) if (volume_key)
cd->volume_key = crypt_alloc_volume_key(volume_key_size, cd->volume_key = crypt_alloc_volume_key(volume_key_size,
volume_key); volume_key);
@@ -1017,6 +1023,9 @@ static int _crypt_format_loopaes(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
if (!(cd->type = strdup(CRYPT_LOOPAES)))
return -ENOMEM;
cd->loopaes_key_size = volume_key_size; cd->loopaes_key_size = volume_key_size;
cd->loopaes_cipher = strdup(cipher ?: DEFAULT_LOOPAES_CIPHER); cd->loopaes_cipher = strdup(cipher ?: DEFAULT_LOOPAES_CIPHER);
@@ -1048,10 +1057,10 @@ static int _crypt_format_verity(struct crypt_device *cd,
if (!params || !params->data_device) if (!params || !params->data_device)
return -EINVAL; return -EINVAL;
/* set data device */ if (!(cd->type = strdup(CRYPT_VERITY)))
cd->type = CRYPT_VERITY; return -ENOMEM;
r = crypt_set_data_device(cd, params->data_device); r = crypt_set_data_device(cd, params->data_device);
cd->type = NULL;
if (r) if (r)
return r; return r;
if (!params->data_size) { if (!params->data_size) {
@@ -1154,10 +1163,9 @@ int crypt_format(struct crypt_device *cd,
r = -EINVAL; r = -EINVAL;
} }
if (!r && !(cd->type = strdup(type)))
r = -ENOMEM;
if (r < 0) { if (r < 0) {
free(cd->type);
cd->type = NULL;
crypt_free_volume_key(cd->volume_key); crypt_free_volume_key(cd->volume_key);
cd->volume_key = NULL; cd->volume_key = NULL;
} }

View File

@@ -38,9 +38,9 @@
#include "libcryptsetup.h" #include "libcryptsetup.h"
#include "internal.h" #include "internal.h"
int crypt_getpagesize(void) unsigned crypt_getpagesize(void)
{ {
return (int)sysconf(_SC_PAGESIZE); return (unsigned)sysconf(_SC_PAGESIZE);
} }
static int get_alignment(int fd) static int get_alignment(int fd)

View File

@@ -31,7 +31,7 @@
static unsigned get_bits_up(size_t u) static unsigned get_bits_up(size_t u)
{ {
unsigned i = 0; unsigned i = 0;
while ((1 << i) < u) while ((1U << i) < u)
i++; i++;
return i; return i;
} }
@@ -39,7 +39,7 @@ static unsigned get_bits_up(size_t u)
static unsigned get_bits_down(size_t u) static unsigned get_bits_down(size_t u)
{ {
unsigned i = 0; unsigned i = 0;
while ((u >> i) > 1) while ((u >> i) > 1U)
i++; i++;
return i; return i;
} }
@@ -103,7 +103,8 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
size_t digest_size_full = 1 << get_bits_up(digest_size); size_t digest_size_full = 1 << get_bits_up(digest_size);
off_t blocks_to_write = (blocks + hash_per_block - 1) / hash_per_block; off_t blocks_to_write = (blocks + hash_per_block - 1) / hash_per_block;
size_t left_bytes; size_t left_bytes;
int i, r; unsigned i;
int r;
if (fseeko(rd, data_block * data_block_size, SEEK_SET)) { if (fseeko(rd, data_block * data_block_size, SEEK_SET)) {
log_dbg("Cannot seek to requested position in data device."); log_dbg("Cannot seek to requested position in data device.");
@@ -377,7 +378,7 @@ int VERITY_create(struct crypt_device *cd,
char *root_hash, char *root_hash,
size_t root_hash_size) size_t root_hash_size)
{ {
int pgsize = crypt_getpagesize(); unsigned pgsize = crypt_getpagesize();
if (verity_hdr->salt_size > 256) if (verity_hdr->salt_size > 256)
return -EINVAL; return -EINVAL;

View File

@@ -49,10 +49,10 @@ static int opt_version_mode = 0;
static const char **action_argv; static const char **action_argv;
static int action_argc; static int action_argc;
static int hex_to_bytes(const char *hex, char *result) static size_t hex_to_bytes(const char *hex, char *result)
{ {
char buf[3] = "xx\0", *endp; char buf[3] = "xx\0", *endp;
int i, len; size_t i, len;
len = strlen(hex) / 2; len = strlen(hex) / 2;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
@@ -178,6 +178,7 @@ static int _activate(const char *dm_device,
struct crypt_params_verity params = {}; struct crypt_params_verity params = {};
uint32_t activate_flags = CRYPT_ACTIVATE_READONLY; uint32_t activate_flags = CRYPT_ACTIVATE_READONLY;
char root_hash_bytes[128]; char root_hash_bytes[128];
size_t hash_size;
int r; int r;
if ((r = crypt_init(&cd, hash_device))) if ((r = crypt_init(&cd, hash_device)))
@@ -199,14 +200,14 @@ static int _activate(const char *dm_device,
if (r < 0) if (r < 0)
goto out; goto out;
if (hex_to_bytes(root_hash, root_hash_bytes) != hash_size = crypt_get_volume_key_size(cd);
crypt_get_volume_key_size(cd)) { if (hex_to_bytes(root_hash, root_hash_bytes) != hash_size) {
r = -EINVAL; r = -EINVAL;
goto out; goto out;
} }
r = crypt_activate_by_volume_key(cd, dm_device, r = crypt_activate_by_volume_key(cd, dm_device,
root_hash_bytes, root_hash_bytes,
crypt_get_volume_key_size(cd), hash_size,
activate_flags); activate_flags);
out: out:
crypt_free(cd); crypt_free(cd);
@@ -251,7 +252,8 @@ static int action_status(int arg)
struct crypt_device *cd = NULL; struct crypt_device *cd = NULL;
struct stat st; struct stat st;
char *backing_file; char *backing_file;
int i, path = 0, r = 0; unsigned i, path = 0;
int r = 0;
/* perhaps a path, not a dm device name */ /* perhaps a path, not a dm device name */
if (strchr(action_argv[0], '/') && !stat(action_argv[0], &st)) if (strchr(action_argv[0], '/') && !stat(action_argv[0], &st))