Declare counter variables within for loops for lowest scope.

This commit is contained in:
syb0rg 2014-04-23 20:04:24 -05:00
parent 9634d0271f
commit b59b665b77
12 changed files with 39 additions and 73 deletions

View File

@ -96,12 +96,11 @@ base128_blksize_enc(void)
inline static void
base128_reverse_init(void)
{
int i;
unsigned char c;
if (!reverse_init) {
memset (rev128, 0, 256);
for (i = 0; i < 128; i++) {
for (int i = 0; i < 128; i++) {
c = cb128[i];
rev128[(int) c] = i;
}

View File

@ -74,12 +74,11 @@ base32_blksize_enc(void)
inline static void
base32_reverse_init(void)
{
int i;
unsigned char c;
if (!reverse_init) {
memset (rev32, 0, 256);
for (i = 0; i < 32; i++) {
for (int i = 0; i < 32; i++) {
c = cb32[i];
rev32[(int) c] = i;
c = cb32_ucase[i];

View File

@ -75,12 +75,11 @@ base64_blksize_enc(void)
inline static void
base64_reverse_init(void)
{
int i;
unsigned char c;
if (!reverse_init) {
memset (rev64, 0, 256);
for (i = 0; i < 64; i++) {
for (int i = 0; i < 64; i++) {
c = cb64[i];
rev64[(int) c] = i;
}

View File

@ -76,12 +76,11 @@ base64u_blksize_enc(void)
inline static void
base64u_reverse_init(void)
{
int i;
unsigned char c;
if (!reverse_init) {
memset (rev64, 0, 256);
for (i = 0; i < 64; i++) {
for (int i = 0; i < 64; i++) {
c = cb64[i];
rev64[(int) c] = i;
}

View File

@ -1835,7 +1835,6 @@ handshake_qtypetest(int dns_fd, int timeout)
char *s = DOWNCODECCHECK1;
int slen = DOWNCODECCHECK1_LEN;
int trycodec;
int k;
if (do_qtype == T_NULL)
trycodec = 'R';
@ -1852,7 +1851,7 @@ handshake_qtypetest(int dns_fd, int timeout)
if (read != slen)
return 0; /* incorrect */
for (k = 0; k < slen; k++) {
for (int k = 0; k < slen; k++) {
if (in[k] != s[k]) {
/* corrupted */
return 0;
@ -1885,8 +1884,6 @@ handshake_qtype_autodetect(int dns_fd)
*/
{
int highestworking = 100;
int timeout;
int qtypenum;
fprintf(stderr, "Autodetecting DNS query type (use -T to override)");
fflush(stderr);
@ -1901,8 +1898,8 @@ handshake_qtype_autodetect(int dns_fd)
to see if things will start working after a while.
*/
for (timeout = 1; running && timeout <= 3; timeout++) {
for (qtypenum = 0; running && qtypenum < highestworking; qtypenum++) {
for (int timeout = 1; running && timeout <= 3; timeout++) {
for (int qtypenum = 0; running && qtypenum < highestworking; qtypenum++) {
do_qtype = handshake_qtype_numcvt(qtypenum);
if (do_qtype == T_UNSET)
break; /* this round finished */
@ -1957,7 +1954,6 @@ handshake_edns0_check(int dns_fd)
*/
{
char in[4096];
int i;
int read;
char *s = DOWNCODECCHECK1;
int slen = DOWNCODECCHECK1_LEN;
@ -1968,7 +1964,7 @@ handshake_edns0_check(int dns_fd)
else
trycodec = 'T';
for (i=0; running && i<3 ;i++) {
for (int i=0; running && i<3 ;i++) {
send_downenctest(dns_fd, trycodec, 1, NULL, 0);
@ -1981,8 +1977,7 @@ handshake_edns0_check(int dns_fd)
return 0; /* reply incorrect = unreliable */
if (read > 0) {
int k;
for (k = 0; k < slen; k++) {
for (int k = 0; k < slen; k++) {
if (in[k] != s[k]) {
/* Definitely not reliable */
return 0;
@ -2003,7 +1998,6 @@ static void
handshake_switch_codec(int dns_fd, int bits)
{
char in[4096];
int i;
int read;
struct encoder *tempenc;
@ -2019,7 +2013,7 @@ handshake_switch_codec(int dns_fd, int bits)
fprintf(stderr, "Switching upstream to codec %s\n", tempenc->name);
for (i=0; running && i<5 ;i++) {
for (int i=0; running && i<5 ;i++) {
send_codec_switch(dns_fd, userid, bits);
@ -2057,7 +2051,6 @@ static void
handshake_switch_downenc(int dns_fd)
{
char in[4096];
int i;
int read;
char *dname;
@ -2072,7 +2065,7 @@ handshake_switch_downenc(int dns_fd)
dname = "Raw";
fprintf(stderr, "Switching downstream to codec %s\n", dname);
for (i=0; running && i<5 ;i++) {
for (int i=0; running && i<5 ;i++) {
send_downenc_switch(dns_fd, userid);
@ -2109,11 +2102,10 @@ static void
handshake_try_lazy(int dns_fd)
{
char in[4096];
int i;
int read;
fprintf(stderr, "Switching to lazy mode for low-latency\n");
for (i=0; running && i<5; i++) {
for (int i=0; running && i<5; i++) {
send_lazy_switch(dns_fd, userid);
@ -2154,10 +2146,9 @@ handshake_lazyoff(int dns_fd)
/* Used in the middle of data transfer, timing is different and no error msgs */
{
char in[4096];
int i;
int read;
for (i=0; running && i<5; i++) {
for (int i=0; running && i<5; i++) {
send_lazy_switch(dns_fd, userid);
@ -2182,8 +2173,8 @@ fragsize_check(char *in, int read, int proposed_fragsize, int *max_fragsize)
{
int acked_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff);
int okay;
int i;
unsigned int v;
int i;
if (read >= 5 && strncmp("BADIP", in, 5) == 0) {
fprintf(stderr, "got BADIP (Try iodined -c)..\n");
@ -2253,7 +2244,6 @@ static int
handshake_autoprobe_fragsize(int dns_fd)
{
char in[4096];
int i;
int read;
int proposed_fragsize = 768;
int range = 768;
@ -2263,7 +2253,7 @@ handshake_autoprobe_fragsize(int dns_fd)
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
while (running && range > 0 && (range >= 8 || max_fragsize < 300)) {
/* stop the slow probing early when we have enough bytes anyway */
for (i=0; running && i<3 ;i++) {
for (int i=0; running && i<3 ;i++) {
send_fragsize_probe(dns_fd, proposed_fragsize);
@ -2327,11 +2317,10 @@ static void
handshake_set_fragsize(int dns_fd, int fragsize)
{
char in[4096];
int i;
int read;
fprintf(stderr, "Setting downstream fragment size to max %d...\n", fragsize);
for (i=0; running && i<5 ;i++) {
for (int i=0; running && i<5 ;i++) {
send_set_downstream_fragsize(dns_fd, fragsize);

View File

@ -59,7 +59,7 @@ const unsigned char raw_header[RAW_HDR_LEN] = { 0x10, 0xd1, 0x9e, 0x00 };
#if !defined(ANDROID) && !defined(WINDOWS32) && !(defined(BSD) && (BSD >= 199306)) && !defined(__GLIBC__)
static int daemon(int nochdir, int noclose)
{
int fd, i;
int fd;
switch (fork()) {
case 0:
@ -80,7 +80,7 @@ static int daemon(int nochdir, int noclose)
if (!noclose) {
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
dup2(fd, i);
}
if (fd > 2) {
@ -293,8 +293,6 @@ read_password(char *buf, size_t len)
tp.c_lflag &= (~ECHO);
tcsetattr(0, TCSANOW, &tp);
#else
int i;
#endif
fprintf(stderr, "Enter password: ");
@ -302,7 +300,7 @@ read_password(char *buf, size_t len)
#ifndef WINDOWS32
fscanf(stdin, "%79[^\n]", pwd);
#else
for (i = 0; i < sizeof(pwd); i++) {
for (int i = 0; i < sizeof(pwd); i++) {
pwd[i] = getch();
if (pwd[i] == '\r' || pwd[i] == '\n') {
pwd[i] = 0;
@ -326,12 +324,10 @@ read_password(char *buf, size_t len)
int
check_topdomain(char *str)
{
int i;
if(str[0] == '.') /* special case */
return 1;
for( i = 0; i < strlen(str); i++) {
for(int i = 0; i < strlen(str); i++) {
if( isalpha(str[i]) || isdigit(str[i]) || str[i] == '-' || str[i] == '.' )
continue;
else
@ -407,8 +403,7 @@ int recent_seqno(int ourseqno, int gotseqno)
Return 0 if gotseqno is new (or very old).
*/
{
int i;
for (i = 0; i < 4; i++, ourseqno--) {
for (int i = 0; i < 4; i++, ourseqno--) {
if (ourseqno < 0)
ourseqno = 7;
if (gotseqno == ourseqno)

View File

@ -508,11 +508,10 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
char names[250][QUERY_NAME_SIZE];
char *rdatastart;
short pref;
int i;
int offset;
memset(names, 0, sizeof(names));
int i;
for (i=0; i < ancount; i++) {
readname(packet, packetlen, &data, name, sizeof(name));
CHECKLEN(12);

View File

@ -37,10 +37,8 @@ void fw_query_put(struct fw_query *fw_query)
void fw_query_get(unsigned short query_id, struct fw_query **fw_query)
{
int i;
*fw_query = NULL;
for (i = 0; i < FW_QUERY_CACHE_SIZE; i++) {
for (int i = 0; i < FW_QUERY_CACHE_SIZE; i++) {
if (fwq[i].id == query_id) {
*fw_query = &(fwq[i]);
return;

View File

@ -35,7 +35,6 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
unsigned char temp[32];
md5_state_t ctx;
int *ix;
int i;
int k;
if (buflen < 16)
@ -44,7 +43,7 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
memcpy(temp, pass, 32);
ix = (int*) temp;
for (i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
k = ntohl(*ix);
k ^= seed;
*ix++ = htonl(k);

View File

@ -181,14 +181,13 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
* right order.
*/
const md5_byte_t *xp = data;
int i;
# if BYTE_ORDER == 0
X = xbuf; /* (dynamic only) */
# else
# define xbuf X /* (static only) */
# endif
for (i = 0; i < 16; ++i, xp += 4)
for (int i = 0; i < 16; ++i, xp += 4)
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
}
#endif
@ -367,16 +366,15 @@ md5_finish(md5_state_t *pms, md5_byte_t digest[16])
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
md5_byte_t data[8];
int i;
/* Save the length before padding. */
for (i = 0; i < 8; ++i)
for (int i = 0; i < 8; ++i)
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
/* Pad to 56 bytes mod 64. */
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
/* Append the length. */
md5_append(pms, data, 8);
for (i = 0; i < 16; ++i)
for (int i = 0; i < 16; ++i)
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}

View File

@ -437,7 +437,6 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
char cmdline[512];
int netmask;
struct in_addr net;
int i;
#ifndef LINUX
int r;
#endif
@ -450,7 +449,7 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
const char *display_ip;
netmask = 0;
for (i = 0; i < netbits; i++) {
for (int i = 0; i < netbits; i++) {
netmask = (netmask << 1) | 1;
}
netmask <<= (32 - netbits);

View File

@ -39,7 +39,6 @@ unsigned usercount;
int
init_users(in_addr_t my_ip, int netbits)
{
int i;
int skip = 0;
char newip[16];
@ -49,7 +48,7 @@ init_users(in_addr_t my_ip, int netbits)
struct in_addr net;
struct in_addr ipstart;
for (i = 0; i < netbits; i++) {
for (int i = 0; i < netbits; i++) {
netmask = (netmask << 1) | 1;
}
netmask <<= (32 - netbits);
@ -60,7 +59,7 @@ init_users(in_addr_t my_ip, int netbits)
usercount = MIN(maxusers, USERS);
users = calloc(usercount, sizeof(struct tun_user));
for (i = 0; i < usercount; i++) {
for (int i = 0; i < usercount; i++) {
in_addr_t ip;
users[i].id = i;
snprintf(newip, sizeof(newip), "0.0.0.%d", i + skip + 1);
@ -92,11 +91,9 @@ users_get_first_ip(void)
int
users_waiting_on_reply(void)
{
int ret;
int i;
int ret = 0;
ret = 0;
for (i = 0; i < usercount; i++) {
for (int i = 0; i < usercount; i++) {
if (users[i].active && !users[i].disabled &&
users[i].last_pkt + 60 > time(NULL) &&
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
@ -110,11 +107,9 @@ users_waiting_on_reply(void)
int
find_user_by_ip(uint32_t ip)
{
int ret;
int i;
int ret = -1;
ret = -1;
for (i = 0; i < usercount; i++) {
for (int i = 0; i < usercount; i++) {
if (users[i].active && !users[i].disabled &&
users[i].last_pkt + 60 > time(NULL) &&
ip == users[i].tun_ip) {
@ -134,12 +129,10 @@ all_users_waiting_to_send(void)
*/
{
time_t now;
int ret;
int i;
ret = 1;
int ret = 1;
now = time(NULL);
for (i = 0; i < usercount; i++) {
for (int i = 0; i < usercount; i++) {
if (users[i].active && !users[i].disabled &&
users[i].last_pkt + 60 > now &&
((users[i].conn == CONN_RAW_UDP) ||
@ -162,8 +155,8 @@ int
find_available_user(void)
{
int ret = -1;
int i;
for (i = 0; i < usercount; i++) {
for (int i = 0; i < usercount; i++) {
/* Not used at all or not used in one minute */
if ((!users[i].active || users[i].last_pkt + 60 < time(NULL)) && !users[i].disabled) {
users[i].active = 1;