It blames comparing signed type with unsigned type.
Fix it in two step:
1. If signed variable is definitely a nonnegative value at the
code context, cast it into unsigned type directly.
2. If it is unclear whether a signed variable is nonnegative, then
add assertion for testing the variable is nonnegative. After
that assertion, cast it into unsigned type. It helps catching
violation that casting negative value into unsigned variable.
Change-Id: Ib4f2a2cb2ad1901518d0726de6035ac4a033bc67
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
ASSERT_RETV(signed_file.signature, ENOMEM, "Not enough memory");
ret = read(signed_file_fd, signed_file.signature, signed_file.signature_size);
- ASSERT_RETV(ret == signed_file.signature_size, errno, "Failed to read signature : %m");
+ ASSERT_RETV(ret >= 0 && (unsigned int)ret == signed_file.signature_size, errno, "Failed to read signature : %m");
signed_file.certificate = malloc(signed_file.certificate_size);
ASSERT_RETV(signed_file.certificate, ENOMEM, "Not enough memory");
ret = read(signed_file_fd, signed_file.certificate, signed_file.certificate_size);
- ASSERT_RETV(ret == signed_file.certificate_size, errno, "Failed to read certificate : %m");
+ ASSERT_RETV(ret >= 0 && (unsigned int)ret == signed_file.certificate_size, errno, "Failed to read certificate : %m");
return SUCCEED;
}
}
ret = write(wHandle, pbBuffer, dwSize);
- if (ret < 0 || ret != dwSize) {
+ if (ret < 0 || (unsigned int)ret != dwSize) {
LOGE(" Failed with return value: %d\n", ret);
LOGL(LOG_SSENGINE, "ret=%d, dwSize=%u write errno=%d\n",
ret, (unsigned int)dwSize, errno);
return E_SS_READ_ERROR;
}
- if (ret != dwSize && ((ret + dwPosition) != (unsigned long)SS_GetFileSize(wHandle)))
+ if ((unsigned int)ret != dwSize && ((ret + dwPosition) != (unsigned long)SS_GetFileSize(wHandle)))
return E_SS_READ_ERROR;
pbBuffer[ret] = '\0';
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/types.h>
if (retry > 0) {
SS_GetAvailableFreeSpace(source_filename, &free_space);
+ assert(patch_data_size > 0);
enough_space = (free_space > (256 << 10)) && // 256k (two-block) minimum
- (free_space > (patch_data_size * 3 / 2)); // 50% margin of error
+ (free_space > (size_t)(patch_data_size * 3 / 2)); // 50% margin of error
}
if (!enough_space) {
LOGL(LOG_SSENGINE, "For %s: free space %ld bytes; enough %d\n", source_filename, (long)free_space,
snprintf(delta_folder, MAX_FOLDER_PATH, "."); // if no "/" in delta path, assume current directory as delta folder
return 0;
}
- if ((pos - s_update_data.ua_delta_path + 1) == strlen(s_update_data.ua_delta_path)) {
+ if ((size_t)(pos - s_update_data.ua_delta_path + 1) == strlen(s_update_data.ua_delta_path)) {
print_usage("Invalid delta path");
return -1;
}
break;
case 3: // kind
- if (kind != -1)
+ if ((int)kind != -1)
return (struct parse_result) { .result = PARSE_REPEATED_ARGUMENT };
if (strcmp(optarg, "raw") == 0)
kind = KIND_RAW;
}
if (help) {
- if (archive != NULL || dest != NULL || archive_file != NULL || patch_orig != NULL || kind != -1)
+ if (archive != NULL || dest != NULL || archive_file != NULL || patch_orig != NULL || (int)kind != -1)
return (struct parse_result) { .result = PARSE_REPEATED_ARGUMENT };
return (struct parse_result) { .result = PARSE_HELP };
}
return (struct parse_result) { .result = PARSE_MISSING_ARGUMENT };
if (archive_file == NULL)
return (struct parse_result) { .result = PARSE_MISSING_ARGUMENT };
- if (kind == -1)
+ if ((int)kind == -1)
return (struct parse_result) { .result = PARSE_MISSING_ARGUMENT };
if (patch_orig == NULL && kind == KIND_BROTLI_PATCH)
SHA1Final(correct_sha1, &context);
char correct_sha1_hex[2 * SHA1_LEN + 1];
- for (int i = 0; i < SHA1_LEN; ++i) {
+ for (unsigned int i = 0; i < SHA1_LEN; ++i) {
correct_sha1_hex[2 * i] = HEX_DIGITS[correct_sha1[i] / 16];
correct_sha1_hex[2 * i + 1] = HEX_DIGITS[correct_sha1[i] % 16];
}
off_t new_offset = offset & (~(getpagesize()-1));
- if (finfo->len - new_offset > MAX_MMAP_LEN) {
+ assert(finfo->len - new_offset >= 0);
+
+ if ((unsigned long long)(finfo->len - new_offset) > MAX_MMAP_LEN) {
// If the rest of the file is greather than MAX_MMAP_LEN
// then we only mmap MAX_MMAP_LEN
finfo->mmapped_len = MAX_MMAP_LEN;
static int remmap_if_needed(struct file_info *finfo)
{
int res = PF_OK;
- if (finfo->pos - (uint8_t*)finfo->ptr >= finfo->mmapped_len) {
+
+ assert(finfo->pos - (uint8_t*)finfo->ptr >= 0);
+
+ if ((size_t)(finfo->pos - (uint8_t*)finfo->ptr) >= finfo->mmapped_len) {
res = remmap_and_save_position(finfo);
}
return res;
return PF_ERROR_DECOMPRESSION;
}
- if (r_read > data->patch_remaining) {
+ assert(r_read >= 0);
+
+ if ((size_t)r_read > data->patch_remaining) {
r_read = data->patch_remaining;
}
data->patch_remaining -= r_read;
return PF_NOT_ENOUGH_DISK_SPACE;
}
- if (data->dest.len == -1) {
+ if (data->dest.len == (size_t)-1) {
data->dest.len = target_size;
if (ftruncate(data->dest.fd, data->dest.len) == -1) {
fprintf(stderr, "Cannot change size of the destination file: %m (%d)\n", errno);
#define SHA1HANDSOFF
+#include <assert.h>
#include <stdio.h>
#include <string.h>
SHA1_CTX ctx;
unsigned int ii;
+ assert(len >= 0);
+
SHA1Init(&ctx);
- for (ii=0; ii<len; ii+=1)
+ for (ii=0; ii<(unsigned int)len; ii+=1)
SHA1Update(&ctx, (const unsigned char*)str + ii, 1);
SHA1Final((unsigned char *)hash_out, &ctx);
}