diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/array.c | 14 | ||||
-rw-r--r-- | src/bitset.c | 4 | ||||
-rw-r--r-- | src/buffer.c | 23 | ||||
-rw-r--r-- | src/buffer.h | 6 | ||||
-rw-r--r-- | src/configfile.c | 14 | ||||
-rw-r--r-- | src/configparser.y | 12 | ||||
-rw-r--r-- | src/connections.c | 2 | ||||
-rw-r--r-- | src/data_string.c | 2 | ||||
-rw-r--r-- | src/fdevent.c | 2 | ||||
-rw-r--r-- | src/fdevent_libev.c | 4 | ||||
-rw-r--r-- | src/fdevent_select.c | 2 | ||||
-rw-r--r-- | src/log.h | 2 | ||||
-rw-r--r-- | src/mod_cgi.c | 6 | ||||
-rw-r--r-- | src/mod_cml_lua.c | 4 | ||||
-rw-r--r-- | src/mod_compress.c | 2 | ||||
-rw-r--r-- | src/mod_dirlisting.c | 8 | ||||
-rw-r--r-- | src/mod_extforward.c | 4 | ||||
-rw-r--r-- | src/mod_fastcgi.c | 24 | ||||
-rw-r--r-- | src/mod_magnet.c | 18 | ||||
-rw-r--r-- | src/mod_magnet_cache.c | 4 | ||||
-rw-r--r-- | src/mod_proxy.c | 4 | ||||
-rw-r--r-- | src/mod_rrdtool.c | 2 | ||||
-rw-r--r-- | src/mod_scgi.c | 12 | ||||
-rw-r--r-- | src/mod_simple_vhost.c | 2 | ||||
-rw-r--r-- | src/mod_webdav.c | 4 | ||||
-rw-r--r-- | src/network_openssl.c | 2 | ||||
-rw-r--r-- | src/network_writev.c | 2 | ||||
-rw-r--r-- | src/server.c | 8 | ||||
-rw-r--r-- | src/settings.h | 6 | ||||
-rw-r--r-- | src/stat_cache.c | 26 |
31 files changed, 120 insertions, 106 deletions
@@ -14,6 +14,7 @@ NEWS * remove logical dead code * [buffer] fix length check in buffer_is_equal_right_len * fix resource leaks in error cases on config parsing and other initializations + * add force_assert() to enforce assertions as simple assert()s are disabled by -DNDEBUG (fixes #2546) - 1.4.34 * [mod_auth] explicitly link ssl for SHA1 (fixes #2517) diff --git a/src/array.c b/src/array.c index 2a3798a6..c9af9958 100644 --- a/src/array.c +++ b/src/array.c @@ -13,7 +13,7 @@ array *array_init(void) { array *a; a = calloc(1, sizeof(*a)); - assert(a); + force_assert(a); a->next_power_of_2 = 1; @@ -74,7 +74,7 @@ void array_reset(array *a) { data_unset *array_pop(array *a) { data_unset *du; - assert(a->used != 0); + force_assert(a->used != 0); a->used --; du = a->data[a->used]; @@ -170,7 +170,7 @@ void array_set_key_value(array *hdrs, const char *key, size_t key_len, const cha data_unset *array_replace(array *a, data_unset *du) { int ndx; - assert(NULL != du); + force_assert(NULL != du); if (-1 == (ndx = array_get_index(a, du->key->ptr, du->key->used, NULL))) { array_insert_unique(a, du); return NULL; @@ -214,15 +214,15 @@ int array_insert_unique(array *a, data_unset *str) { a->size = 16; a->data = malloc(sizeof(*a->data) * a->size); a->sorted = malloc(sizeof(*a->sorted) * a->size); - assert(a->data); - assert(a->sorted); + force_assert(a->data); + force_assert(a->sorted); for (j = a->used; j < a->size; j++) a->data[j] = NULL; } else if (a->size == a->used) { a->size += 16; a->data = realloc(a->data, sizeof(*a->data) * a->size); a->sorted = realloc(a->sorted, sizeof(*a->sorted) * a->size); - assert(a->data); - assert(a->sorted); + force_assert(a->data); + force_assert(a->sorted); for (j = a->used; j < a->size; j++) a->data[j] = NULL; } diff --git a/src/bitset.c b/src/bitset.c index 555f2449..27c93a81 100644 --- a/src/bitset.c +++ b/src/bitset.c @@ -23,12 +23,12 @@ bitset *bitset_init(size_t nbits) { bitset *set; set = malloc(sizeof(*set)); - assert(set); + force_assert(set); set->bits = calloc(BITSET_USED(nbits), sizeof(*set->bits)); set->nbits = nbits; - assert(set->bits); + force_assert(set->bits); return set; } diff --git a/src/buffer.c b/src/buffer.c index aac60b0a..1199164b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -25,7 +25,7 @@ buffer* buffer_init(void) { buffer *b; b = malloc(sizeof(*b)); - assert(b); + force_assert(b); b->ptr = NULL; b->size = 0; @@ -90,7 +90,7 @@ int buffer_prepare_copy(buffer *b, size_t size) { b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); b->ptr = malloc(b->size); - assert(b->ptr); + force_assert(b->ptr); } b->used = 0; return 0; @@ -114,7 +114,7 @@ int buffer_prepare_append(buffer *b, size_t size) { b->ptr = malloc(b->size); b->used = 0; - assert(b->ptr); + force_assert(b->ptr); } else if (b->used + size > b->size) { b->size += size; @@ -122,7 +122,7 @@ int buffer_prepare_append(buffer *b, size_t size) { b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE); b->ptr = realloc(b->ptr, b->size); - assert(b->ptr); + force_assert(b->ptr); } return 0; } @@ -419,7 +419,7 @@ buffer_array* buffer_array_init(void) { b = malloc(sizeof(*b)); - assert(b); + force_assert(b); b->ptr = NULL; b->size = 0; b->used = 0; @@ -463,14 +463,14 @@ buffer *buffer_array_append_get_buffer(buffer_array *b) { if (b->size == 0) { b->size = 16; b->ptr = malloc(sizeof(*b->ptr) * b->size); - assert(b->ptr); + force_assert(b->ptr); for (i = 0; i < b->size; i++) { b->ptr[i] = NULL; } } else if (b->size == b->used) { b->size += 16; b->ptr = realloc(b->ptr, sizeof(*b->ptr) * b->size); - assert(b->ptr); + force_assert(b->ptr); for (i = b->used; i < b->size; i++) { b->ptr[i] = NULL; } @@ -783,7 +783,7 @@ int buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer_ break; } - assert(map != NULL); + force_assert(map != NULL); /* count to-be-encoded-characters */ for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) { @@ -1058,3 +1058,10 @@ int buffer_to_upper(buffer *b) { return 0; } + +void log_failed_assert(const char *filename, unsigned int line, const char *msg) { + /* can't use buffer here; could lead to recursive assertions */ + fprintf(stderr, "%s.%d: %s\n", filename, line, msg); + fflush(stderr); + abort(); +} diff --git a/src/buffer.h b/src/buffer.h index c381652c..20635e2e 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -9,7 +9,6 @@ #include <stdlib.h> #include <sys/types.h> -#include <stdio.h> typedef struct { char *ptr; @@ -127,7 +126,10 @@ int light_isalnum(int c); #define CONST_BUF_LEN(x) x->ptr, x->used ? x->used - 1 : 0 -#define SEGFAULT() do { fprintf(stderr, "%s.%d: aborted\n", __FILE__, __LINE__); abort(); } while(0) #define UNUSED(x) ( (void)(x) ) +void log_failed_assert(const char *filename, unsigned int line, const char *msg) LI_NORETURN; +#define force_assert(x) do { if (!(x)) log_failed_assert(__FILE__, __LINE__, "assertion failed: " #x); } while(0) +#define SEGFAULT() log_failed_assert(__FILE__, __LINE__, "aborted"); + #endif diff --git a/src/configfile.c b/src/configfile.c index 1b788a84..1e96ce09 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -155,13 +155,13 @@ static int config_insert(server *srv) { srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); - assert(srv->config_storage); + force_assert(srv->config_storage); for (i = 0; i < srv->config_context->used; i++) { specific_config *s; s = calloc(1, sizeof(specific_config)); - assert(s); + force_assert(s); s->document_root = buffer_init(); s->mimetypes = array_init(); s->server_name = buffer_init(); @@ -549,7 +549,7 @@ static int tokenizer_close(server *srv, tokenizer_t *t) { #endif static int config_skip_newline(tokenizer_t *t) { int skipped = 1; - assert(t->input[t->offset] == '\r' || t->input[t->offset] == '\n'); + force_assert(t->input[t->offset] == '\r' || t->input[t->offset] == '\n'); if (t->input[t->offset] == '\r' && t->input[t->offset + 1] == '\n') { skipped ++; t->offset ++; @@ -560,7 +560,7 @@ static int config_skip_newline(tokenizer_t *t) { static int config_skip_comment(tokenizer_t *t) { int i; - assert(t->input[t->offset] == '#'); + force_assert(t->input[t->offset] == '#'); for (i = 1; t->input[t->offset + i] && (t->input[t->offset + i] != '\n' && t->input[t->offset + i] != '\r'); i++); @@ -1115,7 +1115,7 @@ int config_read(server *srv, const char *fn) { dc = data_config_init(); buffer_copy_string_len(dc->key, CONST_STR_LEN("global")); - assert(context.all_configs->used == 0); + force_assert(context.all_configs->used == 0); dc->context_ndx = context.all_configs->used; array_insert_unique(context.all_configs, (data_unset *)dc); context.current = dc; @@ -1140,7 +1140,7 @@ int config_read(server *srv, const char *fn) { ret = config_parse_file(srv, &context, fn); /* remains nothing if parser is ok */ - assert(!(0 == ret && context.ok && 0 != context.configs_stack->used)); + force_assert(!(0 == ret && context.ok && 0 != context.configs_stack->used)); context_free(&context); if (0 != ret) { @@ -1172,7 +1172,7 @@ int config_read(server *srv, const char *fn) { } prepends = (data_array *)configparser_merge_data((data_unset *)prepends, (data_unset *)modules); - assert(NULL != prepends); + force_assert(NULL != prepends); buffer_copy_string_buffer(prepends->key, modules->key); array_replace(srv->config, (data_unset *)prepends); modules->free((data_unset *)modules); diff --git a/src/configparser.y b/src/configparser.y index aa6fe98e..efa4afd9 100644 --- a/src/configparser.y +++ b/src/configparser.y @@ -14,7 +14,7 @@ static void configparser_push(config_t *ctx, data_config *dc, int isnew) { if (isnew) { dc->context_ndx = ctx->all_configs->used; - assert(dc->context_ndx > ctx->current->context_ndx); + force_assert(dc->context_ndx > ctx->current->context_ndx); array_insert_unique(ctx->all_configs, (data_unset *)dc); dc->parent = ctx->current; array_insert_unique(dc->parent->childs, (data_unset *)dc); @@ -96,7 +96,7 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) { } break; default: - assert(0); + force_assert(0); break; } } @@ -334,7 +334,7 @@ eols ::= . globalstart ::= GLOBAL. { data_config *dc; dc = (data_config *)array_get_element(ctx->srv->config_context, "global"); - assert(dc); + force_assert(dc); configparser_push(ctx, dc, 0); } @@ -344,7 +344,7 @@ global(A) ::= globalstart LCURLY metalines RCURLY. { cur = ctx->current; configparser_pop(ctx); - assert(cur && ctx->current); + force_assert(cur && ctx->current); A = cur; } @@ -372,7 +372,7 @@ condline(A) ::= context LCURLY metalines RCURLY. { cur = ctx->current; configparser_pop(ctx); - assert(cur && ctx->current); + force_assert(cur && ctx->current); A = cur; } @@ -400,7 +400,7 @@ context ::= DOLLAR SRVVARNAME(B) LBRACKET stringop(C) RBRACKET cond(E) expressio op = buffer_init_string("=~"); break; default: - assert(0); + force_assert(0); return; } diff --git a/src/connections.c b/src/connections.c index 130bcbbc..926b4268 100644 --- a/src/connections.c +++ b/src/connections.c @@ -1034,7 +1034,7 @@ found_header_end: weWant = con->request.content_length - dst_cq->bytes_in; - assert(c->mem->used); + force_assert(c->mem->used); weHave = c->mem->used - c->offset - 1; diff --git a/src/data_string.c b/src/data_string.c index 7648946c..41c9ec17 100644 --- a/src/data_string.c +++ b/src/data_string.c @@ -96,7 +96,7 @@ data_string *data_string_init(void) { data_string *ds; ds = calloc(1, sizeof(*ds)); - assert(ds); + force_assert(ds); ds->key = buffer_init(); ds->value = buffer_init(); diff --git a/src/fdevent.c b/src/fdevent.c index 58f38a72..f3582299 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -136,7 +136,7 @@ int fdevent_unregister(fdevents *ev, int fd) { if (!ev) return 0; fdn = ev->fdarray[fd]; - assert(fdn->events == 0); + force_assert(fdn->events == 0); fdnode_free(fdn); diff --git a/src/fdevent_libev.c b/src/fdevent_libev.c index f6f6b639..fd5268cd 100644 --- a/src/fdevent_libev.c +++ b/src/fdevent_libev.c @@ -67,7 +67,7 @@ static int fdevent_libev_event_set(fdevents *ev, int fde_ndx, int fd, int events if (!watcher) { fdn->handler_ctx = watcher = calloc(1, sizeof(ev_io)); - assert(watcher); + force_assert(watcher); ev_io_init(watcher, io_watcher_cb, fd, ev_events); watcher->data = ev; @@ -103,7 +103,7 @@ static int fdevent_libev_poll(fdevents *ev, int timeout_ms) { ev_init(&timeout_watcher.w, NULL); ev_set_cb(&timeout_watcher.timer, timeout_watcher_cb); timeout_watcher.timer.repeat = ((ev_tstamp) timeout_ms)/1000.0; - assert(timeout_watcher.timer.repeat); + force_assert(timeout_watcher.timer.repeat); ev_timer_again(ev->libev_loop, &timeout_watcher.timer); ev_loop(ev->libev_loop, EVLOOP_ONESHOT); diff --git a/src/fdevent_select.c b/src/fdevent_select.c index 2e23dce8..8e46aa43 100644 --- a/src/fdevent_select.c +++ b/src/fdevent_select.c @@ -38,7 +38,7 @@ static int fdevent_select_event_set(fdevents *ev, int fde_ndx, int fd, int event UNUSED(fde_ndx); /* we should be protected by max-fds, but you never know */ - assert(fd < ((int)FD_SETSIZE)); + force_assert(fd < ((int)FD_SETSIZE)); if (events & FDEVENT_IN) { FD_SET(fd, &(ev->select_set_read)); @@ -8,8 +8,6 @@ */ int openDevNull(int fd); -#define WP() log_error_write(srv, __FILE__, __LINE__, ""); - int open_logfile_or_pipe(server *srv, const char* logfile); int log_error_open(server *srv); diff --git a/src/mod_cgi.c b/src/mod_cgi.c index 9ac9b0dd..734ecee9 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -85,7 +85,7 @@ typedef struct { static handler_ctx * cgi_handler_ctx_init(void) { handler_ctx *hctx = calloc(1, sizeof(*hctx)); - assert(hctx); + force_assert(hctx); hctx->response = buffer_init(); hctx->response_header = buffer_init(); @@ -107,7 +107,7 @@ INIT_FUNC(mod_cgi_init) { p = calloc(1, sizeof(*p)); - assert(p); + force_assert(p); p->tmp_buf = buffer_init(); p->parse_response = buffer_init(); @@ -163,7 +163,7 @@ SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) { plugin_config *s; s = calloc(1, sizeof(plugin_config)); - assert(s); + force_assert(s); s->cgi = array_init(); s->execute_x_only = 0; diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c index 9f4e27a6..92fa6e11 100644 --- a/src/mod_cml_lua.c +++ b/src/mod_cml_lua.c @@ -64,7 +64,7 @@ static int lua_to_c_get_string(lua_State *L, const char *varname, buffer *b) { lua_pop(L, 1); - assert(curelem - 1 == lua_gettop(L)); + force_assert(curelem - 1 == lua_gettop(L)); return 0; } @@ -86,7 +86,7 @@ static int lua_to_c_is_table(lua_State *L, const char *varname) { lua_settop(L, curelem - 1); - assert(curelem - 1 == lua_gettop(L)); + force_assert(curelem - 1 == lua_gettop(L)); return 1; } diff --git a/src/mod_compress.c b/src/mod_compress.c index fb354b30..c4183bbc 100644 --- a/src/mod_compress.c +++ b/src/mod_compress.c @@ -860,7 +860,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) { compression_type = HTTP_ACCEPT_ENCODING_X_GZIP; compression_name = dflt_x_gzip; } else { - assert(matched_encodings & HTTP_ACCEPT_ENCODING_DEFLATE); + force_assert(matched_encodings & HTTP_ACCEPT_ENCODING_DEFLATE); compression_type = HTTP_ACCEPT_ENCODING_DEFLATE; compression_name = dflt_deflate; } diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index 327106dc..cd5809ee 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -672,7 +672,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf #endif path = malloc(dir->used + name_max); - assert(path); + force_assert(path); strcpy(path, dir->ptr); path_file = path + i; @@ -685,11 +685,11 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf } dirs.ent = (dirls_entry_t**) malloc(sizeof(dirls_entry_t*) * DIRLIST_BLOB_SIZE); - assert(dirs.ent); + force_assert(dirs.ent); dirs.size = DIRLIST_BLOB_SIZE; dirs.used = 0; files.ent = (dirls_entry_t**) malloc(sizeof(dirls_entry_t*) * DIRLIST_BLOB_SIZE); - assert(files.ent); + force_assert(files.ent); files.size = DIRLIST_BLOB_SIZE; files.used = 0; @@ -766,7 +766,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf if (list->used == list->size) { list->size += DIRLIST_BLOB_SIZE; list->ent = (dirls_entry_t**) realloc(list->ent, sizeof(dirls_entry_t*) * list->size); - assert(list->ent); + force_assert(list->ent); } tmp = (dirls_entry_t*) malloc(sizeof(dirls_entry_t) + 1 + i); diff --git a/src/mod_extforward.c b/src/mod_extforward.c index eaac3a43..99c4af53 100644 --- a/src/mod_extforward.c +++ b/src/mod_extforward.c @@ -336,11 +336,11 @@ static void ipstr_to_sockaddr(server *srv, const char *host, sock_addr *sock) { } else switch (addrlist->ai_family) { case AF_INET: memcpy(&sock->ipv4, addrlist->ai_addr, sizeof(sock->ipv4)); - assert(AF_INET == sock->plain.sa_family); + force_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); + force_assert(AF_INET6 == sock->plain.sa_family); break; default: log_error_write(srv, __FILE__, __LINE__, "SSS", diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index 1a70da96..641cf0fa 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -487,7 +487,7 @@ static handler_ctx * handler_ctx_init(void) { handler_ctx * hctx; hctx = calloc(1, sizeof(*hctx)); - assert(hctx); + force_assert(hctx); hctx->fde_ndx = -1; @@ -634,7 +634,7 @@ static int fastcgi_extension_insert(fcgi_exts *ext, buffer *key, fcgi_extension_ if (i == ext->used) { /* filextension is new */ fe = calloc(1, sizeof(*fe)); - assert(fe); + force_assert(fe); fe->key = buffer_init(); fe->last_used_ndx = -1; buffer_copy_string_buffer(fe->key, key); @@ -644,11 +644,11 @@ static int fastcgi_extension_insert(fcgi_exts *ext, buffer *key, fcgi_extension_ if (ext->size == 0) { ext->size = 8; ext->exts = malloc(ext->size * sizeof(*(ext->exts))); - assert(ext->exts); + force_assert(ext->exts); } else if (ext->used == ext->size) { ext->size += 8; ext->exts = realloc(ext->exts, ext->size * sizeof(*(ext->exts))); - assert(ext->exts); + force_assert(ext->exts); } ext->exts[ext->used++] = fe; } else { @@ -658,11 +658,11 @@ static int fastcgi_extension_insert(fcgi_exts *ext, buffer *key, fcgi_extension_ if (fe->size == 0) { fe->size = 4; fe->hosts = malloc(fe->size * sizeof(*(fe->hosts))); - assert(fe->hosts); + force_assert(fe->hosts); } else if (fe->size == fe->used) { fe->size += 4; fe->hosts = realloc(fe->hosts, fe->size * sizeof(*(fe->hosts))); - assert(fe->hosts); + force_assert(fe->hosts); } fe->hosts[fe->used++] = fh; @@ -1631,7 +1631,7 @@ static int fcgi_env_add(buffer *env, const char *key, size_t key_len, const char } static int fcgi_header(FCGI_Header * header, unsigned char type, size_t request_id, int contentLength, unsigned char paddingLength) { - assert(contentLength <= FCGI_MAX_LENGTH); + force_assert(contentLength <= FCGI_MAX_LENGTH); header->version = FCGI_VERSION_1; header->type = type; @@ -2094,7 +2094,7 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, size_t request_id) { req_c->file.name); } - assert(weHave != 0); + force_assert(weHave != 0); chunkqueue_append_file(hctx->wb, req_c->file.name, req_c->offset, weHave); @@ -2124,8 +2124,8 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, size_t request_id) { } c = hctx->wb->last; - assert(c->type == FILE_CHUNK); - assert(req_c->file.is_temp == 1); + force_assert(c->type == FILE_CHUNK); + force_assert(req_c->file.is_temp == 1); c->file.is_temp = 1; req_c->file.is_temp = 0; @@ -2541,7 +2541,7 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) { } /* this should be catched by the b > 0 above */ - assert(r); + force_assert(r); b->used = r + 1; /* one extra for the fake \0 */ b->ptr[b->used - 1] = '\0'; @@ -2731,7 +2731,7 @@ static int fcgi_restart_dead_procs(server *srv, plugin_data *p, fcgi_extension_h case PROC_STATE_KILLED: case PROC_STATE_UNSET: /* this should never happen as long as adaptive spawing is disabled */ - assert(0); + force_assert(0); break; case PROC_STATE_RUNNING: diff --git a/src/mod_magnet.c b/src/mod_magnet.c index 643b02aa..7cd4b401 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -696,7 +696,7 @@ static int magnet_copy_response_header(server *srv, connection *con, plugin_data /* lighty.header */ lua_getfield(L, -1, "lighty"); /* lighty.* from the env */ - assert(lua_istable(L, -1)); + force_assert(lua_istable(L, -1)); lua_getfield(L, -1, "header"); /* lighty.header */ if (lua_istable(L, -1)) { @@ -740,11 +740,11 @@ static int magnet_attach_content(server *srv, connection *con, plugin_data *p, l * get the environment of the function */ - assert(lua_isfunction(L, -1)); + force_assert(lua_isfunction(L, -1)); lua_getfenv(L, -1); /* -1 is the function */ lua_getfield(L, -1, "lighty"); /* lighty.* from the env */ - assert(lua_istable(L, -1)); + force_assert(lua_istable(L, -1)); lua_getfield(L, -1, "content"); /* lighty.content */ if (lua_istable(L, -1)) { @@ -875,7 +875,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu lua_pop(L, 1); - assert(lua_gettop(L) == 0); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 0); /* only the function should be on the stack */ con->http_status = 500; con->mode = DIRECT; @@ -997,7 +997,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu lua_tostring(L, -1)); lua_pop(L, 1); /* remove the error-msg and the function copy from the stack */ - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ con->http_status = 500; con->mode = DIRECT; @@ -1007,7 +1007,7 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu lua_remove(L, errfunc); /* we should have the function-copy and the return value on the stack */ - assert(lua_gettop(L) == 2); + force_assert(lua_gettop(L) == 2); if (lua_isnumber(L, -1)) { /* if the ret-value is a number, take it */ @@ -1033,16 +1033,16 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu con->mode = DIRECT; } - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ /* we are finished */ return HANDLER_FINISHED; } else if (MAGNET_RESTART_REQUEST == lua_return_value) { - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ return HANDLER_COMEBACK; } else { - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ return HANDLER_GO_ON; } diff --git a/src/mod_magnet_cache.c b/src/mod_magnet_cache.c index 50326cf8..90c633e2 100644 --- a/src/mod_magnet_cache.c +++ b/src/mod_magnet_cache.c @@ -80,7 +80,7 @@ lua_State *script_cache_get_script(server *srv, connection *con, script_cache *c break; } - assert(lua_isfunction(sc->L, -1)); + force_assert(lua_isfunction(sc->L, -1)); lua_pushvalue(sc->L, -1); /* copy the function-reference */ return sc->L; @@ -128,7 +128,7 @@ lua_State *script_cache_get_script(server *srv, connection *con, script_cache *c * as pcall() will pop the script from the stack when done, we have to * duplicate it here */ - assert(lua_isfunction(sc->L, -1)); + force_assert(lua_isfunction(sc->L, -1)); lua_pushvalue(sc->L, -1); /* copy the function-reference */ return sc->L; diff --git a/src/mod_proxy.c b/src/mod_proxy.c index d57c33cb..957a5a2e 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -686,7 +686,7 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) { } /* this should be catched by the b > 0 above */ - assert(r); + force_assert(r); hctx->response->used += r; hctx->response->ptr[hctx->response->used - 1] = '\0'; @@ -1258,7 +1258,7 @@ static handler_t mod_proxy_check_extension(server *srv, connection *con, void *p } /* just to be sure */ - assert(extension->value->used < INT_MAX); + force_assert(extension->value->used < INT_MAX); host = (data_proxy *)extension->value->data[0]; diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c index 5c5ea881..65d31c23 100644 --- a/src/mod_rrdtool.c +++ b/src/mod_rrdtool.c @@ -346,7 +346,7 @@ SETDEFAULTS_FUNC(mod_rrd_set_defaults) { if (!p) return HANDLER_ERROR; - assert(srv->config_context->used > 0); + force_assert(srv->config_context->used > 0); p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); for (i = 0; i < srv->config_context->used; i++) { diff --git a/src/mod_scgi.c b/src/mod_scgi.c index d1ab78bf..1d99d8b0 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -351,7 +351,7 @@ static handler_ctx * handler_ctx_init(void) { handler_ctx * hctx; hctx = calloc(1, sizeof(*hctx)); - assert(hctx); + force_assert(hctx); hctx->fde_ndx = -1; @@ -495,7 +495,7 @@ static int scgi_extension_insert(scgi_exts *ext, buffer *key, scgi_extension_hos if (i == ext->used) { /* filextension is new */ fe = calloc(1, sizeof(*fe)); - assert(fe); + force_assert(fe); fe->key = buffer_init(); buffer_copy_string_buffer(fe->key, key); @@ -504,11 +504,11 @@ static int scgi_extension_insert(scgi_exts *ext, buffer *key, scgi_extension_hos if (ext->size == 0) { ext->size = 8; ext->exts = malloc(ext->size * sizeof(*(ext->exts))); - assert(ext->exts); + force_assert(ext->exts); } else if (ext->used == ext->size) { ext->size += 8; ext->exts = realloc(ext->exts, ext->size * sizeof(*(ext->exts))); - assert(ext->exts); + force_assert(ext->exts); } ext->exts[ext->used++] = fe; } else { @@ -518,11 +518,11 @@ static int scgi_extension_insert(scgi_exts *ext, buffer *key, scgi_extension_hos if (fe->size == 0) { fe->size = 4; fe->hosts = malloc(fe->size * sizeof(*(fe->hosts))); - assert(fe->hosts); + force_assert(fe->hosts); } else if (fe->size == fe->used) { fe->size += 4; fe->hosts = realloc(fe->hosts, fe->size * sizeof(*(fe->hosts))); - assert(fe->hosts); + force_assert(fe->hosts); } fe->hosts[fe->used++] = fh; diff --git a/src/mod_simple_vhost.c b/src/mod_simple_vhost.c index a3363a1f..1240fda0 100644 --- a/src/mod_simple_vhost.c +++ b/src/mod_simple_vhost.c @@ -124,7 +124,7 @@ SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) { static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) { stat_cache_entry *sce = NULL; - assert(p->conf.server_root->used > 1); + force_assert(p->conf.server_root->used > 1); buffer_prepare_copy(out, 128); buffer_copy_string_buffer(out, p->conf.server_root); diff --git a/src/mod_webdav.c b/src/mod_webdav.c index 5b335142..a7ec31fe 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -1258,7 +1258,7 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { if (1 == webdav_parse_chunkqueue(srv, con, p, con->request_content_queue, &xml)) { xmlNode *rootnode = xmlDocGetRootElement(xml); - assert(rootnode); + force_assert(rootnode); if (0 == xmlStrcmp(rootnode->name, BAD_CAST "propfind")) { xmlNode *cmd; @@ -2235,7 +2235,7 @@ propmatch_cleanup: if (1 == webdav_parse_chunkqueue(srv, con, p, con->request_content_queue, &xml)) { xmlNode *rootnode = xmlDocGetRootElement(xml); - assert(rootnode); + force_assert(rootnode); if (0 == xmlStrcmp(rootnode->name, BAD_CAST "lockinfo")) { xmlNode *lockinfo; diff --git a/src/network_openssl.c b/src/network_openssl.c index 5eb612db..801a6292 100644 --- a/src/network_openssl.c +++ b/src/network_openssl.c @@ -170,7 +170,7 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chu if (NULL == local_send_buffer) { local_send_buffer = malloc(LOCAL_SEND_BUFSIZE); - assert(local_send_buffer); + force_assert(local_send_buffer); } do { diff --git a/src/network_writev.c b/src/network_writev.c index 4c9cb5e3..e9509306 100644 --- a/src/network_writev.c +++ b/src/network_writev.c @@ -273,7 +273,7 @@ int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkq c->file.mmap.length, abs_offset, c->file.mmap.offset); - assert(toSend < 0); + force_assert(toSend < 0); } if (toSend > max_bytes) toSend = max_bytes; diff --git a/src/server.c b/src/server.c index e2b42eb0..3243b7fa 100644 --- a/src/server.c +++ b/src/server.c @@ -172,7 +172,7 @@ static server *server_init(void) { FILE *frandom = NULL; server *srv = calloc(1, sizeof(*srv)); - assert(srv); + force_assert(srv); #define CLEAN(x) \ srv->x = buffer_init(); @@ -230,13 +230,13 @@ static server *server_init(void) { srv->startup_ts = srv->cur_ts; srv->conns = calloc(1, sizeof(*srv->conns)); - assert(srv->conns); + force_assert(srv->conns); srv->joblist = calloc(1, sizeof(*srv->joblist)); - assert(srv->joblist); + force_assert(srv->joblist); srv->fdwaitqueue = calloc(1, sizeof(*srv->fdwaitqueue)); - assert(srv->fdwaitqueue); + force_assert(srv->fdwaitqueue); srv->srvconf.modules = array_init(); srv->srvconf.modules_dir = buffer_init_string(LIBRARY_DIR); diff --git a/src/settings.h b/src/settings.h index 137a0a81..6238be0e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -9,6 +9,12 @@ # define __USE_GNU /* a hack in my eyes, <fcntl.h> F_SETSIG should work with _GNU_SOURCE */ #endif +#ifdef __GNUC__ +# define LI_NORETURN __attribute__((noreturn)) +#else +# define LI_NORETURN +#endif + #define BV(x) (1 << x) #define INET_NTOP_CACHE_MAX 4 diff --git a/src/stat_cache.c b/src/stat_cache.c index 7317d0cc..480aae45 100644 --- a/src/stat_cache.c +++ b/src/stat_cache.c @@ -177,7 +177,7 @@ void stat_cache_free(stat_cache *sc) { stat_cache_entry_free(node->data); sc->files = splaytree_delete(sc->files, node->key); - assert(osize - 1 == splaytree_size(sc->files)); + force_assert(osize - 1 == splaytree_size(sc->files)); } buffer_free(sc->dir_name); @@ -194,9 +194,9 @@ void stat_cache_free(stat_cache *sc) { sc->dirs = splaytree_delete(sc->dirs, node->key); if (osize == 1) { - assert(NULL == sc->dirs); + force_assert(NULL == sc->dirs); } else { - assert(osize == (sc->dirs->size + 1)); + force_assert(osize == (sc->dirs->size + 1)); } } @@ -290,7 +290,7 @@ handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) { fam_dir_entry_free(&sc->fam, node->data); sc->dirs = splaytree_delete(sc->dirs, ndx); - assert(osize - 1 == splaytree_size(sc->dirs)); + force_assert(osize - 1 == splaytree_size(sc->dirs)); } } break; @@ -392,7 +392,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_ if (sc->files && (sc->files->key == file_ndx)) { #ifdef DEBUG_STAT_CACHE /* it was in the cache */ - assert(i < ctrl.used); + force_assert(i < ctrl.used); #endif /* we have seen this file already and @@ -430,7 +430,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_ log_error_write(srv, __FILE__, __LINE__, "xSB", file_ndx, "was already inserted but not found in cache, ", name); } - assert(i == ctrl.used); + force_assert(i == ctrl.used); #endif } @@ -516,9 +516,9 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_ ctrl.ptr[ctrl.used++] = file_ndx; - assert(sc->files); - assert(sc->files->data == sce); - assert(osize + 1 == splaytree_size(sc->files)); + force_assert(sc->files); + force_assert(sc->files->data == sce); + force_assert(osize + 1 == splaytree_size(sc->files)); #endif } @@ -650,9 +650,9 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_ } sc->dirs = splaytree_insert(sc->dirs, dir_ndx, fam_dir); - assert(sc->dirs); - assert(sc->dirs->data == fam_dir); - assert(osize == (sc->dirs->size - 1)); + force_assert(sc->dirs); + force_assert(sc->dirs->data == fam_dir); + force_assert(osize == (sc->dirs->size - 1)); } } else { fam_dir = dir_node->data; @@ -735,7 +735,7 @@ int stat_cache_trigger_cleanup(server *srv) { } } - assert(osize - 1 == splaytree_size(sc->files)); + force_assert(osize - 1 == splaytree_size(sc->files)); #endif } } |