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: Iaf2c9b84dc4fcfc5ae183cb2f2f5ee56de3985b0
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
char lowercase_name[MAX_STRING];
strncpy(lowercase_name, full_var_names[i], MAX_STRING);
lowercase_name[MAX_STRING - 1] = '\0';
- for (int j = 0; j < strlen(lowercase_name); j++)
+ for (size_t j = 0; j < strlen(lowercase_name); j++)
lowercase_name[j] = tolower(lowercase_name[j]);
char to_write[MAX_STRING];
{
int count = 0;
- for (int i = 0; i < strlen(buff); i++)
+ for (size_t i = 0; i < strlen(buff); i++)
{
if (buff[i] == '\n')
count++;
#include <stdio.h>
#include <string.h>
+#include <assert.h>
/* for uint32_t */
#include <stdint.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);
}