2
0
Fork 0

fix bugs and warnings reported by clang

* fix memset sizeof() bugs
 * fix unaligned memory access
 * fix warnings for casts with alignment change
 * crypt_r needs _GNU_SOURCE
This commit is contained in:
Stefan Bühler 2013-06-08 19:45:04 +02:00
parent 392e7bb823
commit 05e058aa9c
8 changed files with 22 additions and 17 deletions

View File

@ -32,7 +32,8 @@
# warning "unknown OS, please report this"
#endif
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE 500
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
# include <lighttpd/config.h>

View File

@ -119,7 +119,7 @@ LI_API gboolean _li_set_sys_error(GError **error, const gchar *msg, const gchar
*
*/
#define LI_CONTAINER_OF(ptr, type, member) \
((type *)( (char *) ptr - offsetof(type, member) ))
((type *)(void *)( (char *) ptr - offsetof(type, member) ))
/* inline implementations */

View File

@ -372,7 +372,7 @@ static gchar *format_char(pcontext *ctx, gchar c) {
static void update_stack(pcontext *ctx) {
g_array_set_size(ctx->g_stack, ctx->top + 1);
ctx->stack = (int*) ctx->g_stack->data;
ctx->stack = &g_array_index(ctx->g_stack, int, 0);
}
static int angel_config_parser_has_error(pcontext *ctx) {
@ -388,7 +388,7 @@ static pcontext* angel_config_parser_new() {
ctx->g_stack = g_array_sized_new(FALSE, FALSE, sizeof(int), 8);
ctx->top = 0;
g_array_set_size(ctx->g_stack, ctx->top + 1);
ctx->stack = (int*) ctx->g_stack->data;
ctx->stack = &g_array_index(ctx->g_stack, int, 0);
ctx->token = g_string_sized_new(0);
ctx->valuestack = g_ptr_array_new();

View File

@ -172,7 +172,7 @@ static int io_events_to_libev(int events) {
}
void li_event_io_init(liEventLoop *loop, liEventIO *io, liEventCallback callback, int fd, int events) {
memset(io, 0, sizeof(io));
memset(io, 0, sizeof(*io));
io->base.type = LI_EVT_IO;
io->base.keep_loop_alive = 1;
io->base.callback = callback;
@ -252,7 +252,7 @@ static void event_timer_cb(struct ev_loop *loop, ev_timer *w, int revents) {
}
void li_event_timer_init(liEventLoop *loop, liEventTimer *timer, liEventCallback callback) {
memset(timer, 0, sizeof(timer));
memset(timer, 0, sizeof(*timer));
timer->base.type = LI_EVT_TIMER;
timer->base.keep_loop_alive = 1;
timer->base.callback = callback;
@ -274,7 +274,7 @@ static void event_async_cb(struct ev_loop *loop, ev_async *w, int revents) {
}
void li_event_async_init(liEventLoop *loop, liEventAsync *async, liEventCallback callback) {
memset(async, 0, sizeof(async));
memset(async, 0, sizeof(*async));
async->base.type = LI_EVT_ASYNC;
async->base.keep_loop_alive = 0;
async->base.callback = callback;
@ -303,7 +303,7 @@ static void event_child_cb(struct ev_loop *loop, ev_child *w, int revents) {
}
void li_event_child_init(liEventLoop *loop, liEventChild *child, liEventCallback callback, int pid) {
memset(child, 0, sizeof(child));
memset(child, 0, sizeof(*child));
child->base.type = LI_EVT_CHILD;
child->base.keep_loop_alive = 1;
child->base.callback = callback;
@ -327,7 +327,7 @@ static void event_signal_cb(struct ev_loop *loop, ev_signal *w, int revents) {
}
void li_event_signal_init(liEventLoop *loop, liEventSignal *sig, liEventCallback callback, int signum) {
memset(sig, 0, sizeof(sig));
memset(sig, 0, sizeof(*sig));
sig->base.type = LI_EVT_SIGNAL;
sig->base.keep_loop_alive = 0;
sig->base.callback = callback;
@ -351,7 +351,7 @@ static void event_prepare_cb(struct ev_loop *loop, ev_prepare *w, int revents) {
}
void li_event_prepare_init(liEventLoop *loop, liEventPrepare *prepare, liEventCallback callback) {
memset(prepare, 0, sizeof(prepare));
memset(prepare, 0, sizeof(*prepare));
prepare->base.type = LI_EVT_PREPARE;
prepare->base.keep_loop_alive = 0;
prepare->base.callback = callback;
@ -374,7 +374,7 @@ static void event_check_cb(struct ev_loop *loop, ev_check *w, int revents) {
}
void li_event_check_init(liEventLoop *loop, liEventCheck *check, liEventCallback callback) {
memset(check, 0, sizeof(check));
memset(check, 0, sizeof(*check));
check->base.type = LI_EVT_CHECK;
check->base.keep_loop_alive = 0;
check->base.callback = callback;

View File

@ -113,7 +113,7 @@ gboolean li_parse_ipv4(const char *str, guint32 *ip, guint32 *netmask, guint16 *
gboolean li_parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *port) {
guint8 data[4] = {0,0,0,0};
guint16 *predata = (guint16*) ip, postdata[8];
guint16 predata[8], postdata[8];
size_t prec = 0, postc = 0;
const char *p = str, *mark = NULL;
gboolean res = TRUE, compressed = FALSE;
@ -134,13 +134,14 @@ gboolean li_parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *por
if (prec + postc > 7) return FALSE;
for ( ; prec < 8-postc; prec++) predata[prec] = 0;
for (postc = 0 ; prec < 8; prec++, postc++ ) predata[prec] = postdata[postc];
memcpy(ip, predata, 16);
return TRUE;
}
GString* li_ipv6_tostring(GString *dest, const guint8 ip[16]) {
#define IPV6_TEMPLATE "ffff:ffff:ffff:ffff:ffff:ffff:abc.def.ghi.jkl"
guint16 *data = (guint16*) ip;
guint16 data[8];
size_t i;
#ifdef HAVE_INET_NTOP
@ -150,6 +151,7 @@ GString* li_ipv6_tostring(GString *dest, const guint8 ip[16]) {
return dest;
}
#endif
memcpy(data, ip, 16);
g_string_truncate(dest, 0);
g_string_printf(dest, "%" G_GINT16_MODIFIER "x", ntohs(data[0]));
for (i = 1; i < 8; i++) {

View File

@ -190,7 +190,7 @@ static inline void mp_free_page(const void *ptr, gsize size) {
munmap((void*) ptr, size);
# else
UNUSED(size);
g_free(ptr);
g_free((void*) ptr);
# endif
#ifdef WITH_PROFILER

View File

@ -674,13 +674,15 @@ gboolean li_ipv6_in_ipv6_net(const unsigned char *target, const guint8 *match, g
gboolean li_ipv6_in_ipv4_net(const unsigned char *target, guint32 match, guint32 networkmask) {
static const guint8 ipv6match[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
guint32 v4_target;
if (!li_ipv6_in_ipv6_net(target, ipv6match, 96)) return FALSE;
return li_ipv4_in_ipv4_net(*(guint32*)(target+12), match, networkmask);
memcpy(&v4_target, target + 12, 4);
return li_ipv4_in_ipv4_net(v4_target, match, networkmask);
}
gboolean li_ipv4_in_ipv6_net(guint32 target, const guint8 *match, guint network) {
guint8 ipv6[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
*(guint32*) (ipv6+12) = target;
memcpy(ipv6+12, &target, 4);
return li_ipv6_in_ipv6_net(ipv6, match, network);
}

View File

@ -67,7 +67,7 @@ liNetworkStatus li_network_backend_writev(int fd, liChunkQueue *cq, goffset *wri
(STRING_CHUNK == (c = li_chunkiter_chunk(ci))->type || MEM_CHUNK == c->type || BUFFER_CHUNK == c->type) &&
chunks->len < UIO_MAXIOV);
while (-1 == (r = writev(fd, (struct iovec*) chunks->data, chunks->len))) {
while (-1 == (r = writev(fd, &g_array_index(chunks, struct iovec, 0), chunks->len))) {
switch (errno) {
case EAGAIN:
#if EWOULDBLOCK != EAGAIN