improve compilation flags

- more / specific warnings enabled
 - specify c std
This commit is contained in:
Jethro Grassie 2019-08-06 22:43:45 -04:00
parent 01b2f3274c
commit 0d8479a3b2
No known key found for this signature in database
GPG key ID: DE8ED755616565BB
2 changed files with 72 additions and 37 deletions

View file

@ -64,30 +64,27 @@ OS := $(shell uname -s)
CPPDEFS = _GNU_SOURCE AUTO_INITIALIZE_EASYLOGGINGPP LOG_USE_COLOR CPPDEFS = _GNU_SOURCE AUTO_INITIALIZE_EASYLOGGINGPP LOG_USE_COLOR
CCPARAM = -Wall $(CFLAGS) -maes -fPIC W = -W -Wall -Wno-unused-parameter -Wuninitialized
CXXFLAGS = -std=c++11 -Wno-reorder 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) ifeq ($(OS), Darwin)
CXXFLAGS += -stdlib=libc++ CXXFLAGS += -stdlib=libc++
CPPDEFS += HAVE_MEMSET_S CPPDEFS += HAVE_MEMSET_S
endif
ifeq ($(OS),Darwin)
LDPARAM = LDPARAM =
else
LDPARAM = -Wl,-warn-unresolved-symbols -fPIC -pie
endif endif
ifeq ($(TYPE),debug) ifeq ($(TYPE),debug)
CCPARAM += -g CFLAGS += -g
CXXFLAGS += -g
CPPDEFS += DEBUG CPPDEFS += DEBUG
endif endif
ifeq ($(TYPE), release) ifeq ($(TYPE), release)
CCPARAM += -O3 -Wno-unused-variable CFLAGS += -O3
ifneq ($(OS), Darwin) CXXFLAGS += -O3
LDPARAM = -Wl,--unresolved-symbols=ignore-in-object-files
endif
endif endif
LDPARAM += $(LDFLAGS) LDPARAM += $(LDFLAGS)
@ -160,7 +157,7 @@ $(TARGET): preflight dirs $(OBJECTS) $(COBJECTS) $(SOBJECTS) $(HTMLOBJECTS)
$(STORE)/%.o: %.cpp $(STORE)/%.o: %.cpp
@echo Creating object file for $*... @echo Creating object file for $*...
$(C++) -Wp,-MMD,$(STORE)/$*.dd $(CCPARAM) $(CXXFLAGS) \ $(C++) -Wp,-MMD,$(STORE)/$*.dd $(CXXFLAGS) \
$(foreach INC,$(INCPATH),-I$(INC)) \ $(foreach INC,$(INCPATH),-I$(INC)) \
$(PKG_INC) \ $(PKG_INC) \
$(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) \ $(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) \
@ -171,7 +168,7 @@ $(STORE)/%.o: %.cpp
$(STORE)/%.o: %.c $(STORE)/%.o: %.c
@echo Creating object file for $*... @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 INC,$(INCPATH),-I$(INC)) $(PKG_INC) \
$(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) -c $< -o $@ $(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) -c $< -o $@
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' \ @sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' \
@ -180,7 +177,7 @@ $(STORE)/%.o: %.c
$(STORE)/%.o: %.S $(STORE)/%.o: %.S
@echo Creating object file for $*... @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 INC,$(INCPATH),-I$(INC)) $(PKG_INC) \
$(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) -c $< -o $@ $(foreach CPPDEF,$(CPPDEFS),-D$(CPPDEF)) -c $< -o $@
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' \ @sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' \
@ -190,7 +187,7 @@ $(STORE)/%.o: %.S
$(STORE)/%.o: %.html $(STORE)/%.o: %.html
@echo Creating object file for $*... @echo Creating object file for $*...
xxd -i $< | sed -e 's/src_//' -e 's/embed_//' > $(STORE)/$*.c 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 @rm -f $(STORE)/$*.c
# Empty rule to prevent problems when a header is deleted. # Empty rule to prevent problems when a header is deleted.

View file

@ -248,10 +248,14 @@ static unsigned char pub_spend[32];
#define JSON_GET_OR_ERROR(name, parent, type, client) \ #define JSON_GET_OR_ERROR(name, parent, type, client) \
json_object *name = NULL; \ json_object *name = NULL; \
if (!json_object_object_get_ex(parent, #name, &name)) \ if (!json_object_object_get_ex(parent, #name, &name)) { \
return send_validation_error(client, #name " not found"); \ send_validation_error(client, #name " not found"); \
if (!json_object_is_type(name, type)) \ return; \
return send_validation_error(client, #name " not a " #type); } \
if (!json_object_is_type(name, type)) { \
send_validation_error(client, #name " not a " #type); \
return; \
}
#define JSON_GET_OR_WARN(name, parent, type) \ #define JSON_GET_OR_WARN(name, parent, type) \
json_object *name = NULL; \ json_object *name = NULL; \
@ -406,7 +410,7 @@ database_close(void)
mdb_dbi_close(env, db_blocks); mdb_dbi_close(env, db_blocks);
mdb_dbi_close(env, db_balance); mdb_dbi_close(env, db_balance);
mdb_dbi_close(env, db_payments); mdb_dbi_close(env, db_payments);
return mdb_env_close(env); mdb_env_close(env);
} }
static int static int
@ -692,7 +696,7 @@ process_blocks(block_t *blocks, size_t count)
return rc; return rc;
} }
for (int i=0; i<count; i++) for (size_t i=0; i<count; i++)
{ {
block_t *ib = &blocks[i]; block_t *ib = &blocks[i];
log_trace("Processing block at height %"PRIu64, ib->height); log_trace("Processing block at height %"PRIu64, ib->height);
@ -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); JSON_GET_OR_WARN(headers, result, json_type_array);
size_t headers_len = json_object_array_length(headers); size_t headers_len = json_object_array_length(headers);
assert(headers_len == BLOCK_HEADERS_RANGE); assert(headers_len == BLOCK_HEADERS_RANGE);
for (int i=0; i<headers_len; i++) for (size_t i=0; i<headers_len; i++)
{ {
json_object *header = json_object_array_get_idx(headers, i); json_object *header = json_object_array_get_idx(headers, i);
block_t *bh = &block_headers_range[i]; block_t *bh = &block_headers_range[i];
@ -1975,8 +1979,9 @@ client_on_login(json_object *message, client_t *client)
{ {
if (config.disable_self_select) if (config.disable_self_select)
{ {
return send_validation_error(client, send_validation_error(client,
"pool disabled self-select"); "pool disabled self-select");
return;
} }
client->mode = MODE_SELF_SELECT; client->mode = MODE_SELF_SELECT;
log_trace("Client login for 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; uint64_t prefix;
parse_address(address, &prefix, NULL); parse_address(address, &prefix, NULL);
if (prefix != MAINNET_ADDRESS_PREFIX && prefix != TESTNET_ADDRESS_PREFIX) 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"); "login only main wallet addresses are supported");
return;
}
const char *worker_id = json_object_get_string(pass); 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) 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"); "login mode self-select and proxy not yet supported");
return;
} }
strncpy(client->address, address, sizeof(client->address)); 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); const char *jid = json_object_get_string(job_id);
if (strlen(jid) != 32) 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 h = json_object_get_int64(height);
int64_t dh = llabs(h - (int64_t)pool_stats.network_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]; char m[64];
snprintf(m, 64, "Bad height. Differs to pool by %"PRIu64" blocks.", dh); 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); 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) if (rc != 0)
{ {
log_warn("Bad template submitted: %d", rc); 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); job_t *job = client_find_job(client, jid);
if (!job) 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) 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 = calloc(1, sizeof(block_template_t));
job->miner_template->blocktemplate_blob = strdup(btb); job->miner_template->blocktemplate_blob = strdup(btb);
@ -2088,22 +2108,37 @@ client_on_submit(json_object *message, client_t *client)
errno = 0; errno = 0;
unsigned long int uli = strtoul(nptr, &endptr, 16); unsigned long int uli = strtoul(nptr, &endptr, 16);
if (errno != 0 || nptr == endptr) 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 uint32_t result_nonce = ntohl(uli);
const char *result_hex = json_object_get_string(result); const char *result_hex = json_object_get_string(result);
if (strlen(result_hex) != 64) 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) 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); const char *jid = json_object_get_string(job_id);
if (strlen(jid) != 32) 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); job_t *job = client_find_job(client, jid);
if (!job) 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", log_trace("Client submitted nonce=%u, result=%s",
result_nonce, result_hex); result_nonce, result_hex);
@ -2127,7 +2162,10 @@ client_on_submit(json_object *message, client_t *client)
/* Convert template to blob */ /* Convert template to blob */
if (client->mode == MODE_SELF_SELECT && !job->miner_template) 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; block_template_t *bt;
if (job->miner_template) if (job->miner_template)
bt = job->miner_template; bt = job->miner_template;