Skip to content

Commit

Permalink
Compiler fixes for gcc 10
Browse files Browse the repository at this point in the history
This patch fixes a few compile warnings/errors that now occur when using gcc
10+.

Also, the Makefile.rules check to turn off partial inlining in gcc versions
greater or equal to 8.2.1 had a bug where it only it only checked against
versions with at least 3 numbers (ex: 8.2.1 vs 10). This patch now ensures
any version above the specified version is correctly compared.

Change-Id: I54718496eb0c3ce5bd6d427cd279a29e8d2825f9
  • Loading branch information
kharwell authored and Friendly Automation committed Jun 10, 2020
1 parent 559fa0e commit 3d1bf3c
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 89 deletions.
19 changes: 10 additions & 9 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,23 @@ else
endif

OPTIMIZE?=-O3

ifneq ($(findstring darwin,$(OSARCH)),)
ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
# Snow Leopard/Lion has an issue with this optimization flag on large files (like chan_sip)
OPTIMIZE+=-fno-inline-functions
endif
endif

# gcc version 8.2.1 and above must have partial-inlining disabled to avoid documented bug.
# We must handle cross-compiling and clang so make sure the compiler version string has "gcc"
# somewhere in it before testing the version.
CC_VERS_STRING=$(shell $(CC) --version | grep -i gcc)
ifneq ($(CC_VERS_STRING),)
GCC_VER_GTE821:=$(shell expr `echo '$(CC_VERS_STRING)' | cut -d ' ' -f 3 | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/'` \>= 80201)
ifeq ($(GCC_VER_GTE821),1)
OPTIMIZE+=-fno-partial-inlining
endif
ifeq ($(CC),gcc)
# gcc version 8.2.1 and above must have partial-inlining disabled in order
# to avoid a documented bug. Sort to make the lowest version number come
# first. If it's the specified version then the current gcc version is equal
# to or greater, so add the custom optimization rule.
gcc_versions=$(shell printf "%s\n" $$(gcc -dumpversion) 8.2.1 | sort -n)
ifeq ($(firstword $(gcc_versions)),8.2.1)
OPTIMIZE+=-fno-partial-inlining
endif
endif

ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
Expand Down
10 changes: 7 additions & 3 deletions addons/ooh323c/src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,10 @@ static int decodeOctets
nbits -= 8;
}

if (nbits <= 0) {
return ASN_OK;
}

/* Copy last partial byte */

if (nbits >= rshift) {
Expand All @@ -752,7 +756,7 @@ static int decodeOctets

pctxt->buffer.bitOffset = 8 - nbitsInLastOctet;
}
else if (nbits > 0) { /* nbits < rshift */
else { /* nbits > 0 && nbits < rshift */
pbuffer[i] =
pctxt->buffer.data[pctxt->buffer.byteIndex] << lshift;
pctxt->buffer.bitOffset = rshift - nbits;
Expand Down Expand Up @@ -832,8 +836,8 @@ int decodeOpenType

int decodeSemiConsInteger (OOCTXT* pctxt, ASN1INT* pvalue, ASN1INT lower)
{
signed char b;
unsigned char ub;
signed char b = 0;
unsigned char ub = 0;
ASN1UINT nbytes;
int stat;

Expand Down
2 changes: 1 addition & 1 deletion addons/ooh323c/src/ooSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ int ooSocketAccept (OOSOCKET socket, OOSOCKET *pNewSocket,

if (destAddr != 0) {
if ((host = ast_sockaddr_stringify_addr(&addr)) != NULL)
strncpy(destAddr, host, strlen(host));
memcpy(destAddr, host, strlen(host) + 1);
}
if (destPort != 0)
*destPort = ast_sockaddr_port(&addr);
Expand Down
2 changes: 1 addition & 1 deletion addons/ooh323c/src/oochannels.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ int ooAcceptH225Connection()
call->callToken);

if (remoteIP[0]) {
strncpy(call->remoteIP, remoteIP, strlen(remoteIP));
memcpy(call->remoteIP, remoteIP, strlen(remoteIP) + 1);
}

ast_mutex_unlock(&call->Lock);
Expand Down
11 changes: 6 additions & 5 deletions apps/app_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,14 @@ static void gosub_release_frame(struct ast_channel *chan, struct gosub_stack_fra
static struct gosub_stack_frame *gosub_allocate_frame(const char *context, const char *extension, int priority, int in_subroutine, unsigned char arguments)
{
struct gosub_stack_frame *new = NULL;
int len_extension = strlen(extension), len_context = strlen(context);
int len_extension = strlen(extension) + 1;
int len_context = strlen(context) + 1;

if ((new = ast_calloc(1, sizeof(*new) + 2 + len_extension + len_context))) {
if ((new = ast_calloc(1, sizeof(*new) + len_extension + len_context))) {
AST_LIST_HEAD_INIT_NOLOCK(&new->varshead);
strcpy(new->extension, extension);
new->context = new->extension + len_extension + 1;
strcpy(new->context, context);
ast_copy_string(new->extension, extension, len_extension);
new->context = new->extension + len_extension;
ast_copy_string(new->context, context, len_context);
new->priority = priority;
new->in_subroutine = in_subroutine ? 1 : 0;
new->arguments = arguments;
Expand Down
22 changes: 12 additions & 10 deletions apps/app_voicemail.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,12 @@ static int inprocess_cmp_fn(void *obj, void *arg, int flags)

static int inprocess_count(const char *context, const char *mailbox, int delta)
{
struct inprocess *i, *arg = ast_alloca(sizeof(*arg) + strlen(context) + strlen(mailbox) + 2);
arg->context = arg->mailbox + strlen(mailbox) + 1;
strcpy(arg->mailbox, mailbox); /* SAFE */
strcpy(arg->context, context); /* SAFE */
int context_len = strlen(context) + 1;
int mailbox_len = strlen(mailbox) + 1;
struct inprocess *i, *arg = ast_alloca(sizeof(*arg) + context_len + mailbox_len);
arg->context = arg->mailbox + mailbox_len;
ast_copy_string(arg->mailbox, mailbox, mailbox_len); /* SAFE */
ast_copy_string(arg->context, context, context_len); /* SAFE */
ao2_lock(inprocess_container);
if ((i = ao2_find(inprocess_container, arg, 0))) {
int ret = ast_atomic_fetchadd_int(&i->count, delta);
Expand All @@ -1129,13 +1131,13 @@ static int inprocess_count(const char *context, const char *mailbox, int delta)
if (delta < 0) {
ast_log(LOG_WARNING, "BUG: ref count decrement on non-existing object???\n");
}
if (!(i = ao2_alloc(sizeof(*i) + strlen(context) + strlen(mailbox) + 2, NULL))) {
if (!(i = ao2_alloc(sizeof(*i) + context_len + mailbox_len, NULL))) {
ao2_unlock(inprocess_container);
return 0;
}
i->context = i->mailbox + strlen(mailbox) + 1;
strcpy(i->mailbox, mailbox); /* SAFE */
strcpy(i->context, context); /* SAFE */
i->context = i->mailbox + mailbox_len;
ast_copy_string(i->mailbox, mailbox, mailbox_len); /* SAFE */
ast_copy_string(i->context, context, context_len); /* SAFE */
i->count = delta;
ao2_link(inprocess_container, i);
ao2_unlock(inprocess_container);
Expand Down Expand Up @@ -13564,8 +13566,8 @@ static struct alias_mailbox_mapping *alias_mailbox_mapping_create(const char *al
}
mapping->alias = mapping->buf;
mapping->mailbox = mapping->buf + from_len;
strcpy(mapping->alias, alias); /* Safe */
strcpy(mapping->mailbox, mailbox); /* Safe */
ast_copy_string(mapping->alias, alias, from_len); /* Safe */
ast_copy_string(mapping->mailbox, mailbox, to_len); /* Safe */

return mapping;
}
Expand Down
7 changes: 5 additions & 2 deletions include/asterisk/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,14 @@ int ast_app_group_list_unlock(void);
\note This defines a structure type, but does not declare an instance
of the structure. That must be done separately.
*/

#define AST_DEFINE_APP_ARGS_TYPE(type, arglist) \
struct type { \
unsigned int argc; \
char *argv[0]; \
arglist \
union { \
char *argv[sizeof(struct {arglist}) / sizeof(char *)]; \
struct {arglist}; \
}; \
}

/*!
Expand Down
6 changes: 4 additions & 2 deletions main/dns_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *da
struct ast_dns_srv_record *srv;
int host_size;
char host[NI_MAXHOST] = "";
size_t host_len;

ptr = dns_find_record(data, size, query->result->answer, query->result->answer_size);
ast_assert(ptr != NULL);
Expand Down Expand Up @@ -89,7 +90,8 @@ struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *da
return NULL;
}

srv = ast_calloc(1, sizeof(*srv) + size + strlen(host) + 1);
host_len = strlen(host) + 1;
srv = ast_calloc(1, sizeof(*srv) + size + host_len);
if (!srv) {
return NULL;
}
Expand All @@ -99,7 +101,7 @@ struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *da
srv->port = port;

srv->host = srv->data + size;
strcpy((char *)srv->host, host); /* SAFE */
ast_copy_string((char *)srv->host, host, host_len); /* SAFE */
srv->generic.data_ptr = srv->data;

return (struct ast_dns_record *)srv;
Expand Down
6 changes: 4 additions & 2 deletions main/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,7 @@ static void add_redirect(const char *value)
struct http_uri_redirect *redirect, *cur;
unsigned int target_len;
unsigned int total_len;
size_t dest_len;

dest = ast_strdupa(value);
dest = ast_skip_blanks(dest);
Expand All @@ -2038,14 +2039,15 @@ static void add_redirect(const char *value)
}

target_len = strlen(target) + 1;
total_len = sizeof(*redirect) + target_len + strlen(dest) + 1;
dest_len = strlen(dest) + 1;
total_len = sizeof(*redirect) + target_len + dest_len;

if (!(redirect = ast_calloc(1, total_len))) {
return;
}
redirect->dest = redirect->target + target_len;
strcpy(redirect->target, target);
strcpy(redirect->dest, dest);
ast_copy_string(redirect->dest, dest, dest_len);

AST_RWLIST_WRLOCK(&uri_redirects);

Expand Down
2 changes: 1 addition & 1 deletion main/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ void __ast_trace(const char *file, int line, const char *func, enum ast_trace_in
va_list ap;
unsigned long indent = (unsigned long)ast_threadstorage_get_ptr(&trace_indent);
struct ast_str *fmt = ast_str_create(128);
char *direction;
const char *direction = "";

if (!fmt) {
return;
Expand Down
2 changes: 1 addition & 1 deletion main/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ struct ast_msg_data *ast_msg_data_alloc(enum ast_msg_data_source_type source,
/* Set the ones we have and increment the offset */
for (i=0; i < count; i++) {
len = (strlen(attributes[i].value) + 1);
strcpy(msg->buf + current_offset, attributes[i].value); /* Safe */
ast_copy_string(msg->buf + current_offset, attributes[i].value, len); /* Safe */
msg->attribute_value_offsets[attributes[i].type] = current_offset;
current_offset += len;
}
Expand Down
7 changes: 5 additions & 2 deletions main/pbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6519,14 +6519,17 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, struct ast_
i = ao2_iterator_init(hints, AO2_ITERATOR_DONTLOCK);
for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
if (ao2_container_count(hint->callbacks)) {
size_t exten_len;

ao2_lock(hint);
if (!hint->exten) {
/* The extension has already been destroyed. (Should never happen here) */
ao2_unlock(hint);
continue;
}

length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2
exten_len = strlen(hint->exten->exten) + 1;
length = exten_len + strlen(hint->exten->parent->name) + 1
+ sizeof(*saved_hint);
if (!(saved_hint = ast_calloc(1, length))) {
ao2_unlock(hint);
Expand All @@ -6546,7 +6549,7 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, struct ast_
saved_hint->context = saved_hint->data;
strcpy(saved_hint->data, hint->exten->parent->name);
saved_hint->exten = saved_hint->data + strlen(saved_hint->context) + 1;
strcpy(saved_hint->exten, hint->exten->exten);
ast_copy_string(saved_hint->exten, hint->exten->exten, exten_len);
if (hint->last_presence_subtype) {
saved_hint->last_presence_subtype = ast_strdup(hint->last_presence_subtype);
}
Expand Down
8 changes: 2 additions & 6 deletions main/pbx_variables.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,10 @@ static const char *ast_str_substring(struct ast_str *value, int offset, int leng
}

if (length >= 0 && length < lr) { /* truncate if necessary */
char *tmp = ast_str_buffer(value);
tmp[length] = '\0';
ast_str_update(value);
ast_str_truncate(value, length);
} else if (length < 0) {
if (lr > -length) { /* After we remove from the front and from the rear, is there anything left? */
char *tmp = ast_str_buffer(value);
tmp[lr + length] = '\0';
ast_str_update(value);
ast_str_truncate(value, lr + length);
} else {
ast_str_reset(value);
}
Expand Down
12 changes: 8 additions & 4 deletions main/stasis.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ static int link_topic_proxy(struct stasis_topic *topic, const char *name, const
{
struct topic_proxy *proxy;
struct stasis_topic* topic_tmp;
size_t detail_len;

if (!topic || !name || !strlen(name) || !detail) {
return -1;
Expand All @@ -514,8 +515,10 @@ static int link_topic_proxy(struct stasis_topic *topic, const char *name, const
return -1;
}

detail_len = strlen(detail) + 1;

proxy = ao2_t_weakproxy_alloc(
sizeof(*proxy) + strlen(name) + 1 + strlen(detail) + 1, NULL, name);
sizeof(*proxy) + strlen(name) + 1 + detail_len, NULL, name);
if (!proxy) {
ao2_unlock(topic_all);

Expand All @@ -527,7 +530,7 @@ static int link_topic_proxy(struct stasis_topic *topic, const char *name, const
proxy->detail = proxy->name + strlen(name) + 1;

strcpy(proxy->name, name); /* SAFE */
strcpy(proxy->detail, detail); /* SAFE */
ast_copy_string(proxy->detail, detail, detail_len); /* SAFE */
proxy->creationtime = ast_tvnow();

/* We have exclusive access to proxy, no need for locking here. */
Expand Down Expand Up @@ -1620,17 +1623,18 @@ static void subscription_change_dtor(void *obj)
static struct stasis_subscription_change *subscription_change_alloc(struct stasis_topic *topic, const char *uniqueid, const char *description)
{
size_t description_len = strlen(description) + 1;
size_t uniqueid_len = strlen(uniqueid) + 1;
struct stasis_subscription_change *change;

change = ao2_alloc_options(sizeof(*change) + description_len + strlen(uniqueid) + 1,
change = ao2_alloc_options(sizeof(*change) + description_len + uniqueid_len,
subscription_change_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
if (!change) {
return NULL;
}

strcpy(change->description, description); /* SAFE */
change->uniqueid = change->description + description_len;
strcpy(change->uniqueid, uniqueid); /* SAFE */
ast_copy_string(change->uniqueid, uniqueid, uniqueid_len); /* SAFE */
ao2_ref(topic, +1);
change->topic = topic;

Expand Down
4 changes: 2 additions & 2 deletions main/stasis_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static struct ast_channel_snapshot_peer *channel_snapshot_peer_create(struct ast

strcpy(snapshot->account, peeraccount); /* Safe */
snapshot->linkedid = snapshot->account + peeraccount_len;
strcpy(snapshot->linkedid, linkedid); /* Safe */
ast_copy_string(snapshot->linkedid, linkedid, linkedid_len); /* Safe */

return snapshot;
}
Expand Down Expand Up @@ -370,7 +370,7 @@ static struct ast_channel_snapshot_connected *channel_snapshot_connected_create(

strcpy(snapshot->name, name); /* Safe */
snapshot->number = snapshot->name + name_len;
strcpy(snapshot->number, number); /* Safe */
ast_copy_string(snapshot->number, number, number_len); /* Safe */

return snapshot;
}
Expand Down
15 changes: 7 additions & 8 deletions pbx/pbx_dundi.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ static void *dundi_precache_thread(void *data)
{
struct dundi_query_state *st = data;
struct dundi_ie_data ied;
struct dundi_hint_metadata hmd;
struct dundi_hint_metadata hmd = {0};
char eid_str[20];

ast_debug(1, "Whee, precaching '%s@%s' for '%s'\n", st->called_number, st->called_context,
Expand Down Expand Up @@ -3936,7 +3936,6 @@ int dundi_lookup(struct dundi_result *result, int maxret, struct ast_channel *ch

static void reschedule_precache(const char *number, const char *context, int expiration)
{
int len;
struct dundi_precache_queue *qe, *prev;

AST_LIST_LOCK(&pcq);
Expand All @@ -3948,16 +3947,16 @@ static void reschedule_precache(const char *number, const char *context, int exp
}
AST_LIST_TRAVERSE_SAFE_END;
if (!qe) {
len = sizeof(*qe);
len += strlen(number) + 1;
len += strlen(context) + 1;
if (!(qe = ast_calloc(1, len))) {
int len = sizeof(*qe);
int num_len = strlen(number) + 1;
int context_len = strlen(context) + 1;
if (!(qe = ast_calloc(1, len + num_len + context_len))) {
AST_LIST_UNLOCK(&pcq);
return;
}
strcpy(qe->number, number);
qe->context = qe->number + strlen(number) + 1;
strcpy(qe->context, context);
qe->context = qe->number + num_len + 1;
ast_copy_string(qe->context, context, context_len);
}
time(&qe->expiration);
qe->expiration += expiration;
Expand Down
Loading

0 comments on commit 3d1bf3c

Please sign in to comment.