fix undefined stuff found with clang
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2873 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
parent
661efa3f37
commit
a0e93c678b
1
NEWS
1
NEWS
|
@ -14,6 +14,7 @@ NEWS
|
|||
* [mod_auth] add htpasswd -s (SHA1) support if openssl is used (needs openssl for SHA1). This doesn't use any salt, md5 with salt is probably better.
|
||||
* [mod_auth] fix base64_decode (#2484)
|
||||
* fix some bugs found with canalyze (fixes #2484, thx Zhenbo Xu)
|
||||
* fix undefined stuff found with clang
|
||||
|
||||
- 1.4.32 - 2012-11-21
|
||||
* Code cleanup with clang/sparse (fixes #2437, thx kibi)
|
||||
|
|
69
src/buffer.c
69
src/buffer.c
|
@ -7,6 +7,11 @@
|
|||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if defined HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#elif defined HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
static const char hex_chars[] = "0123456789abcdef";
|
||||
|
||||
|
@ -533,60 +538,32 @@ int buffer_is_equal_string(buffer *a, const char *s, size_t b_len) {
|
|||
return buffer_is_equal(a, &b);
|
||||
}
|
||||
|
||||
/* simple-assumption:
|
||||
*
|
||||
* most parts are equal and doing a case conversion needs time
|
||||
*
|
||||
*/
|
||||
|
||||
int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len) {
|
||||
size_t ndx = 0, max_ndx;
|
||||
size_t *al, *bl;
|
||||
size_t mask = sizeof(*al) - 1;
|
||||
size_t const len = (a_len < b_len) ? a_len : b_len;
|
||||
size_t i;
|
||||
|
||||
al = (size_t *)a;
|
||||
bl = (size_t *)b;
|
||||
for (i = 0; i < len; ++i) {
|
||||
unsigned char ca = a[i], cb = b[i];
|
||||
if (ca == cb) continue;
|
||||
|
||||
/* is the alignment correct ? */
|
||||
if ( ((size_t)al & mask) == 0 &&
|
||||
((size_t)bl & mask) == 0 ) {
|
||||
|
||||
max_ndx = ((a_len < b_len) ? a_len : b_len) & ~mask;
|
||||
|
||||
for (; ndx < max_ndx; ndx += sizeof(*al)) {
|
||||
if (*al != *bl) break;
|
||||
al++; bl++;
|
||||
|
||||
}
|
||||
/* always lowercase for transitive results */
|
||||
#if 1
|
||||
if (ca >= 'A' && ca <= 'Z') ca |= 32;
|
||||
if (cb >= 'A' && cb <= 'Z') cb |= 32;
|
||||
#else
|
||||
/* try to produce code without branching (jumps) */
|
||||
ca |= ((unsigned char)(ca - (unsigned char)'A') <= (unsigned char)('Z' - 'A')) ? 32 : 0;
|
||||
cb |= ((unsigned char)(cb - (unsigned char)'A') <= (unsigned char)('Z' - 'A')) ? 32 : 0;
|
||||
#endif
|
||||
|
||||
if (ca == cb) continue;
|
||||
return ca - cb;
|
||||
}
|
||||
|
||||
a = (char *)al;
|
||||
b = (char *)bl;
|
||||
|
||||
max_ndx = ((a_len < b_len) ? a_len : b_len);
|
||||
|
||||
for (; ndx < max_ndx; ndx++) {
|
||||
int a1 = *a++, b1 = *b++;
|
||||
|
||||
if (a1 != b1) {
|
||||
/* always lowercase for transitive results */
|
||||
if (a1 >= 'A' && a1 <= 'Z') a1 |= 32;
|
||||
if (b1 >= 'A' && b1 <= 'Z') b1 |= 32;
|
||||
|
||||
if ((a1 - b1) != 0) return (a1 - b1);
|
||||
}
|
||||
}
|
||||
|
||||
/* all chars are the same, and the length match too
|
||||
*
|
||||
* they are the same */
|
||||
if (a_len == b_len) return 0;
|
||||
|
||||
/* if a is shorter then b, then b is larger */
|
||||
return (a_len - b_len);
|
||||
return a_len - b_len;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if the rightmost bytes of the string are equal.
|
||||
*
|
||||
|
|
10
src/lemon.c
10
src/lemon.c
|
@ -3105,7 +3105,7 @@ int mhflag; /* True if generating makeheaders output */
|
|||
stddt[j] = 0;
|
||||
hash = 0;
|
||||
for(j=0; stddt[j]; j++){
|
||||
hash = hash*53 + stddt[j];
|
||||
hash = (unsigned int)hash*53u + (unsigned int) stddt[j];
|
||||
}
|
||||
hash = (hash & 0x7fffffff)%arraysize;
|
||||
while( types[hash] ){
|
||||
|
@ -3751,8 +3751,8 @@ char *s2;
|
|||
PRIVATE int strhash(x)
|
||||
char *x;
|
||||
{
|
||||
int h = 0;
|
||||
while( *x) h = h*13 + *(x++);
|
||||
unsigned int h = 0;
|
||||
while( *x) h = h*13u + (unsigned int) *(x++);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@ -4124,9 +4124,9 @@ struct config *b;
|
|||
PRIVATE int statehash(a)
|
||||
struct config *a;
|
||||
{
|
||||
int h=0;
|
||||
unsigned int h=0;
|
||||
while( a ){
|
||||
h = h*571 + a->rp->index*37 + a->dot;
|
||||
h = h*571u + (unsigned int)a->rp->index*37u + (unsigned int)a->dot;
|
||||
a = a->bp;
|
||||
}
|
||||
return h;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -303,11 +304,14 @@ static const char *last_not_in_array(array *a, plugin_data *p)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct addrinfo *ipstr_to_sockaddr(server *srv, const char *host) {
|
||||
struct addrinfo hints, *res0;
|
||||
#ifdef HAVE_IPV6
|
||||
static void ipstr_to_sockaddr(server *srv, const char *host, sock_addr *sock) {
|
||||
struct addrinfo hints, *addrlist = NULL;
|
||||
int result;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
sock->plain.sa_family = AF_UNSPEC;
|
||||
|
||||
#ifndef AI_NUMERICSERV
|
||||
/**
|
||||
* quoting $ man getaddrinfo
|
||||
|
@ -321,22 +325,31 @@ static struct addrinfo *ipstr_to_sockaddr(server *srv, const char *host) {
|
|||
hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
|
||||
|
||||
errno = 0;
|
||||
result = getaddrinfo(host, NULL, &hints, &res0);
|
||||
result = getaddrinfo(host, NULL, &hints, &addrlist);
|
||||
|
||||
if (result != 0) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "SSSs(S)",
|
||||
"could not resolve hostname ", host, " because ", gai_strerror(result), strerror(errno));
|
||||
|
||||
return NULL;
|
||||
} else if (res0 == NULL) {
|
||||
"could not parse ip address ", host, " because ", gai_strerror(result), strerror(errno));
|
||||
} else if (addrlist == NULL) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "SSS",
|
||||
"Problem in resolving hostname ", host, ": succeeded, but no information returned");
|
||||
"Problem in parsing ip address ", host, ": succeeded, but no information returned");
|
||||
} else switch (addrlist->ai_family) {
|
||||
case AF_INET:
|
||||
memcpy(&sock->ipv4, addrlist->ai_addr, sizeof(sock->ipv4));
|
||||
assert(AF_INET == sock->plain.sa_family);
|
||||
break;
|
||||
case AF_INET6:
|
||||
memcpy(&sock->ipv6, addrlist->ai_addr, sizeof(sock->ipv6));
|
||||
assert(AF_INET6 == sock->plain.sa_family);
|
||||
break;
|
||||
default:
|
||||
log_error_write(srv, __FILE__, __LINE__, "SSS",
|
||||
"Problem in parsing ip address ", host, ": succeeded, but unknown family");
|
||||
}
|
||||
|
||||
return res0;
|
||||
freeaddrinfo(addrlist);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static void clean_cond_cache(server *srv, connection *con) {
|
||||
config_cond_cache_reset_item(srv, con, COMP_HTTP_REMOTE_IP);
|
||||
|
@ -347,7 +360,6 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) {
|
|||
data_string *forwarded = NULL;
|
||||
#ifdef HAVE_IPV6
|
||||
char b2[INET6_ADDRSTRLEN + 1];
|
||||
struct addrinfo *addrlist = NULL;
|
||||
#endif
|
||||
const char *dst_addr_str = NULL;
|
||||
array *forward_array = NULL;
|
||||
|
@ -411,7 +423,6 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) {
|
|||
|
||||
if (real_remote_addr != NULL) { /* parsed */
|
||||
sock_addr sock;
|
||||
struct addrinfo *addrs_left;
|
||||
server_socket *srv_sock = con->srv_socket;
|
||||
data_string *forwarded_proto = (data_string *)array_get_element(con->request.headers, "X-Forwarded-Proto");
|
||||
|
||||
|
@ -425,18 +436,7 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) {
|
|||
log_error_write(srv, __FILE__, __LINE__, "ss", "using address:", real_remote_addr);
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
addrlist = ipstr_to_sockaddr(srv, real_remote_addr);
|
||||
sock.plain.sa_family = AF_UNSPEC;
|
||||
for (addrs_left = addrlist; addrs_left != NULL; addrs_left = addrs_left -> ai_next) {
|
||||
sock.plain.sa_family = addrs_left->ai_family;
|
||||
if (sock.plain.sa_family == AF_INET) {
|
||||
sock.ipv4.sin_addr = ((struct sockaddr_in*)addrs_left->ai_addr)->sin_addr;
|
||||
break;
|
||||
} else if (sock.plain.sa_family == AF_INET6) {
|
||||
sock.ipv6.sin6_addr = ((struct sockaddr_in6*)addrs_left->ai_addr)->sin6_addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ipstr_to_sockaddr(srv, real_remote_addr, &sock);
|
||||
#else
|
||||
UNUSED(addrs_left);
|
||||
sock.ipv4.sin_addr.s_addr = inet_addr(real_remote_addr);
|
||||
|
@ -464,9 +464,6 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) {
|
|||
/* Now, clean the conf_cond cache, because we may have changed the results of tests */
|
||||
clean_cond_cache(srv, con);
|
||||
}
|
||||
#ifdef HAVE_IPV6
|
||||
if (addrlist != NULL ) freeaddrinfo(addrlist);
|
||||
#endif
|
||||
}
|
||||
array_free(forward_array);
|
||||
|
||||
|
|
|
@ -437,7 +437,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
|
|||
return HANDLER_FINISHED;
|
||||
}
|
||||
|
||||
last_hit = *(time_t *)(val.dptr);
|
||||
memcpy(&last_hit, val.dptr, sizeof(time_t));
|
||||
|
||||
free(val.dptr);
|
||||
|
||||
|
@ -555,7 +555,7 @@ TRIGGER_FUNC(mod_trigger_b4_dl_handle_trigger) {
|
|||
|
||||
val = gdbm_fetch(s->db, key);
|
||||
|
||||
last_hit = *(time_t *)(val.dptr);
|
||||
memcpy(&last_hit, val.dptr, sizeof(time_t));
|
||||
|
||||
free(val.dptr);
|
||||
|
||||
|
|
Loading…
Reference in New Issue