From 0d8479a3b2f5d3509b77779c41720c2c1fe17dcc Mon Sep 17 00:00:00 2001 From: Jethro Grassie Date: Tue, 6 Aug 2019 22:43:45 -0400 Subject: [PATCH] improve compilation flags - more / specific warnings enabled - specify c std --- Makefile | 29 +++++++++----------- src/pool.c | 80 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 72 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index dedfcc8..35810f4 100644 --- a/Makefile +++ b/Makefile @@ -64,30 +64,27 @@ OS := $(shell uname -s) CPPDEFS = _GNU_SOURCE AUTO_INITIALIZE_EASYLOGGINGPP LOG_USE_COLOR -CCPARAM = -Wall $(CFLAGS) -maes -fPIC -CXXFLAGS = -std=c++11 -Wno-reorder +W = -W -Wall -Wno-unused-parameter -Wuninitialized +OPT = -maes -fPIC +CFLAGS = $(W) -Wbad-function-cast $(OPT) -std=c99 +CXXFLAGS = $(W) -Wno-reorder $(OPT) -std=c++11 +LDPARAM = -fPIC -pie ifeq ($(OS), Darwin) CXXFLAGS += -stdlib=libc++ CPPDEFS += HAVE_MEMSET_S -endif - -ifeq ($(OS),Darwin) LDPARAM = -else - LDPARAM = -Wl,-warn-unresolved-symbols -fPIC -pie endif ifeq ($(TYPE),debug) - CCPARAM += -g + CFLAGS += -g + CXXFLAGS += -g CPPDEFS += DEBUG endif ifeq ($(TYPE), release) - CCPARAM += -O3 -Wno-unused-variable - ifneq ($(OS), Darwin) - LDPARAM = -Wl,--unresolved-symbols=ignore-in-object-files - endif + CFLAGS += -O3 + CXXFLAGS += -O3 endif LDPARAM += $(LDFLAGS) @@ -160,7 +157,7 @@ $(TARGET): preflight dirs $(OBJECTS) $(COBJECTS) $(SOBJECTS) $(HTMLOBJECTS) $(STORE)/%.o: %.cpp @echo Creating object file for $*... - $(C++) -Wp,-MMD,$(STORE)/$*.dd $(CCPARAM) $(CXXFLAGS) \ + $(C++) -Wp,-MMD,$(STORE)/$*.dd $(CXXFLAGS) \ $(foreach INC,$(INCPATH),-I$(INC)) \ $(PKG_INC) \ $(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) \ @@ -171,7 +168,7 @@ $(STORE)/%.o: %.cpp $(STORE)/%.o: %.c @echo Creating object file for $*... - $(CC) -Wp,-MMD,$(STORE)/$*.dd $(CCPARAM) \ + $(CC) -Wp,-MMD,$(STORE)/$*.dd $(CFLAGS) \ $(foreach INC,$(INCPATH),-I$(INC)) $(PKG_INC) \ $(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) -c $< -o $@ @sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' \ @@ -180,7 +177,7 @@ $(STORE)/%.o: %.c $(STORE)/%.o: %.S @echo Creating object file for $*... - $(CC) -Wp,-MMD,$(STORE)/$*.dd $(CCPARAM) \ + $(CC) -Wp,-MMD,$(STORE)/$*.dd $(CFLAGS) \ $(foreach INC,$(INCPATH),-I$(INC)) $(PKG_INC) \ $(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) -c $< -o $@ @sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' \ @@ -190,7 +187,7 @@ $(STORE)/%.o: %.S $(STORE)/%.o: %.html @echo Creating object file for $*... xxd -i $< | sed -e 's/src_//' -e 's/embed_//' > $(STORE)/$*.c - $(CC) $(CCPARAM) -c $(STORE)/$*.c -o $@ + $(CC) $(CFLAGS) -c $(STORE)/$*.c -o $@ @rm -f $(STORE)/$*.c # Empty rule to prevent problems when a header is deleted. diff --git a/src/pool.c b/src/pool.c index d3ca3e6..037c351 100644 --- a/src/pool.c +++ b/src/pool.c @@ -248,10 +248,14 @@ static unsigned char pub_spend[32]; #define JSON_GET_OR_ERROR(name, parent, type, client) \ json_object *name = NULL; \ - if (!json_object_object_get_ex(parent, #name, &name)) \ - return send_validation_error(client, #name " not found"); \ - if (!json_object_is_type(name, type)) \ - return send_validation_error(client, #name " not a " #type); + if (!json_object_object_get_ex(parent, #name, &name)) { \ + send_validation_error(client, #name " not found"); \ + return; \ + } \ + if (!json_object_is_type(name, type)) { \ + send_validation_error(client, #name " not a " #type); \ + return; \ + } #define JSON_GET_OR_WARN(name, parent, type) \ json_object *name = NULL; \ @@ -406,7 +410,7 @@ database_close(void) mdb_dbi_close(env, db_blocks); mdb_dbi_close(env, db_balance); mdb_dbi_close(env, db_payments); - return mdb_env_close(env); + mdb_env_close(env); } static int @@ -692,7 +696,7 @@ process_blocks(block_t *blocks, size_t count) return rc; } - for (int i=0; iheight); @@ -1403,7 +1407,7 @@ rpc_on_block_headers_range(const char* data, rpc_callback_t *callback) JSON_GET_OR_WARN(headers, result, json_type_array); size_t headers_len = json_object_array_length(headers); assert(headers_len == BLOCK_HEADERS_RANGE); - for (int i=0; imode = MODE_SELF_SELECT; log_trace("Client login for mode: self-select"); @@ -1988,8 +1993,11 @@ client_on_login(json_object *message, client_t *client) uint64_t prefix; parse_address(address, &prefix, NULL); if (prefix != MAINNET_ADDRESS_PREFIX && prefix != TESTNET_ADDRESS_PREFIX) - return send_validation_error(client, + { + send_validation_error(client, "login only main wallet addresses are supported"); + return; + } const char *worker_id = json_object_get_string(pass); @@ -2007,8 +2015,9 @@ client_on_login(json_object *message, client_t *client) if (client->is_proxy && client->mode == MODE_SELF_SELECT) { - return send_validation_error(client, + send_validation_error(client, "login mode self-select and proxy not yet supported"); + return; } strncpy(client->address, address, sizeof(client->address)); @@ -2034,7 +2043,10 @@ client_on_block_template(json_object *message, client_t *client) const char *jid = json_object_get_string(job_id); if (strlen(jid) != 32) - return send_validation_error(client, "job_id invalid length"); + { + send_validation_error(client, "job_id invalid length"); + return; + } int64_t h = json_object_get_int64(height); int64_t dh = llabs(h - (int64_t)pool_stats.network_height); @@ -2042,7 +2054,8 @@ client_on_block_template(json_object *message, client_t *client) { char m[64]; snprintf(m, 64, "Bad height. Differs to pool by %"PRIu64" blocks.", dh); - return send_validation_error(client, m); + send_validation_error(client, m); + return; } const char *btb = json_object_get_string(blob); @@ -2050,15 +2063,22 @@ client_on_block_template(json_object *message, client_t *client) if (rc != 0) { log_warn("Bad template submitted: %d", rc); - return send_validation_error(client, "block template blob invalid"); + send_validation_error(client, "block template blob invalid"); + return; } job_t *job = client_find_job(client, jid); if (!job) - return send_validation_error(client, "cannot find job with job_id"); + { + send_validation_error(client, "cannot find job with job_id"); + return; + } if (job->miner_template) - return send_validation_error(client, "job already has block template"); + { + send_validation_error(client, "job already has block template"); + return; + } job->miner_template = calloc(1, sizeof(block_template_t)); job->miner_template->blocktemplate_blob = strdup(btb); @@ -2088,22 +2108,37 @@ client_on_submit(json_object *message, client_t *client) errno = 0; unsigned long int uli = strtoul(nptr, &endptr, 16); if (errno != 0 || nptr == endptr) - return send_validation_error(client, "nonce not an unsigned long int"); + { + send_validation_error(client, "nonce not an unsigned long int"); + return; + } const uint32_t result_nonce = ntohl(uli); const char *result_hex = json_object_get_string(result); if (strlen(result_hex) != 64) - return send_validation_error(client, "result invalid length"); + { + send_validation_error(client, "result invalid length"); + return; + } if (is_hex_string(result_hex) != 0) - return send_validation_error(client, "result not hex string"); + { + send_validation_error(client, "result not hex string"); + return; + } const char *jid = json_object_get_string(job_id); if (strlen(jid) != 32) - return send_validation_error(client, "job_id invalid length"); + { + send_validation_error(client, "job_id invalid length"); + return; + } job_t *job = client_find_job(client, jid); if (!job) - return send_validation_error(client, "cannot find job with job_id"); + { + send_validation_error(client, "cannot find job with job_id"); + return; + } log_trace("Client submitted nonce=%u, result=%s", result_nonce, result_hex); @@ -2127,7 +2162,10 @@ client_on_submit(json_object *message, client_t *client) /* Convert template to blob */ if (client->mode == MODE_SELF_SELECT && !job->miner_template) - return send_validation_error(client, "mode self-selct and no template"); + { + send_validation_error(client, "mode self-selct and no template"); + return; + } block_template_t *bt; if (job->miner_template) bt = job->miner_template;