From 57abe9d22d7513aea247d4944db2e55110f67613 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 18 Oct 2007 01:01:20 +0000 Subject: [PATCH] Fix compiler warning: conversion from "int" to "unsigned char" may lose significant bits --- ares_init.c | 10 +++++----- ares_query.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ares_init.c b/ares_init.c index e37ac7b..b5b841f 100644 --- a/ares_init.c +++ b/ares_init.c @@ -1349,7 +1349,7 @@ static void randomize_key(unsigned char* key,int key_data_len) if ( !randomized ) { for (;counterstate[0]; for(counter = 0; counter < 256; counter++) /* unnecessary AND but it keeps some compilers happier */ - state[counter] = counter & 0xff; + state[counter] = (unsigned char)(counter & 0xff); key->x = 0; key->y = 0; index1 = 0; index2 = 0; for(counter = 0; counter < 256; counter++) { - index2 = (key_data_ptr[index1] + state[counter] + - index2) % 256; + index2 = (unsigned char)((key_data_ptr[index1] + state[counter] + + index2) % 256); ARES_SWAP_BYTE(&state[counter], &state[index2]); - index1 = (index1 + 1) % key_data_len; + index1 = (unsigned char)((index1 + 1) % key_data_len); } free(key_data_ptr); return ARES_SUCCESS; diff --git a/ares_query.c b/ares_query.c index c7c31ed..3959c0e 100644 --- a/ares_query.c +++ b/ares_query.c @@ -53,13 +53,13 @@ void ares__rc4(rc4_key* key, unsigned char *buffer_ptr, int buffer_len) state = &key->state[0]; for(counter = 0; counter < buffer_len; counter ++) { - x = (x + 1) % 256; - y = (state[x] + y) % 256; - ARES_SWAP_BYTE(&state[x], &state[y]); + x = (unsigned char)((x + 1) % 256); + y = (unsigned char)((state[x] + y) % 256); + ARES_SWAP_BYTE(&state[x], &state[y]); - xorIndex = (state[x] + state[y]) % 256; + xorIndex = (unsigned char)((state[x] + state[y]) % 256); - buffer_ptr[counter] ^= state[xorIndex]; + buffer_ptr[counter] = (unsigned char)(buffer_ptr[counter]^state[xorIndex]); } key->x = x; key->y = y; -- 2.7.4