[Asterisk-code-review] Several fixes for compiling on macOS (asterisk[15])

David M. Lee asteriskteam at digium.com
Sun Dec 31 20:56:51 CST 2017


David M. Lee has uploaded this change for review. ( https://gerrit.asterisk.org/7778


Change subject: Several fixes for compiling on macOS
......................................................................

Several fixes for compiling on macOS

 * Remove macosx-version-min. It's unnecessary, and we do a really bad
   job of keeping it up to date (10.6 has been EOL for over three years)

 * Ignore self-assign errors when using clang. This is a false positive
   with code like `x = ltohl(x)`

 * Fix some signed char issues

 * Fix compat macros for strlcat and strlcpy when the system defines
   them as macros

 * Add clang pragmas to `AST_VECTOR_INSERT_AT()` to avoid tautology
   errors

 * Fix format spec problems in `res_config_pgsql`. Apparently there's
   disagreement between compilers as to whether the math results in an
   unsigned char or an integer, so I assigned it to an int to remove the
   ambiguitry.

 * Fix undeclared identifier bugs recently introduced in show sysinfo

 * Fix "taking absolute value of unsigned type" warning in translate.c,
   because somebody decided it would be a good idea that the difference
   between two unsigned types ought to still be unsigned for some
   reason.

Change-Id: I3900881168c570c4177bf394caf33562e5c67f94
---
M Makefile
M Makefile.rules
M apps/app_adsiprog.c
M apps/app_sms.c
M include/asterisk/compat.h
M include/asterisk/vector.h
M main/Makefile
M main/asterisk.c
M main/translate.c
M res/res_config_pgsql.c
M res/res_http_websocket.c
11 files changed, 30 insertions(+), 26 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/78/7778/1

diff --git a/Makefile b/Makefile
index afd50c3..1130ec5 100644
--- a/Makefile
+++ b/Makefile
@@ -269,9 +269,8 @@
 MOD_SUBDIRS_MENUSELECT_TREE:=$(MOD_SUBDIRS:%=%-menuselect-tree)
 
 ifneq ($(findstring darwin,$(OSARCH)),)
-  _ASTCFLAGS+=-D__Darwin__ -mmacosx-version-min=10.6
-  _SOLINK=-mmacosx-version-min=10.6 -Wl,-undefined,dynamic_lookup
-  _SOLINK+=/usr/lib/bundle1.o
+  _ASTCFLAGS+=-D__Darwin__
+  _SOLINK=-Wl,-undefined,dynamic_lookup
   SOLINK=-bundle $(_SOLINK)
   DYLINK=-Wl,-dylib $(_SOLINK)
   _ASTLDFLAGS+=-L/usr/local/lib
diff --git a/Makefile.rules b/Makefile.rules
index 2273644..813acbf 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -91,7 +91,7 @@
 
 # Clang -Werror warning suppressions
 ifeq ($(C_COMPILER_FAMILY),clang)
-	CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
+	CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality -Wno-self-assign
 endif
 
 ifeq ($(GNU_LD),1)
diff --git a/apps/app_adsiprog.c b/apps/app_adsiprog.c
index 0659029..4307abf 100644
--- a/apps/app_adsiprog.c
+++ b/apps/app_adsiprog.c
@@ -1109,7 +1109,7 @@
 				tmp[7] = '\0';
 			}
 			/* Setup initial stuff */
-			state->key->retstr[0] = 128;
+			state->key->retstr[0] = (char) 128;
 			/* 1 has the length */
 			state->key->retstr[2] = state->key->id;
 			/* Put the Full name in */
@@ -1145,7 +1145,7 @@
 				break;
 			}
 			/* Setup sub */
-			state->sub->data[0] = 130;
+			state->sub->data[0] = (char) 130;
 			/* 1 is the length */
 			state->sub->data[2] = 0x0; /* Clear extensibility bit */
 			state->sub->datalen = 3;
@@ -1262,7 +1262,7 @@
 				/* Something bad happened */
 				break;
 			}
-			disp->data[0] = 129;
+			disp->data[0] = (char) 129;
 			disp->data[1] = disp->datalen - 2;
 			disp->data[2] = ((lrci & 0x3) << 6) | disp->id;
 			disp->data[3] = wi;
diff --git a/apps/app_sms.c b/apps/app_sms.c
index 88985fb..f2a1a22 100644
--- a/apps/app_sms.c
+++ b/apps/app_sms.c
@@ -807,7 +807,7 @@
 					*p++ = '\\';
 					*p++ = 'r';
 				} else if (h->ud[n] < 32 || h->ud[n] == 127) {
-					*p++ = 191;
+					*p++ = (char) 191;
 				} else {
 					*p++ = h->ud[n];
 				}
diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h
index 2e89a39..024e8a8 100644
--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -124,7 +124,10 @@
 void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff);
 #endif
 
+#undef	strlcat
 #define	strlcat	__use__ast_str__functions_not__strlcat__
+
+#undef	strlcpy
 #define	strlcpy	__use__ast_copy_string__not__strlcpy__
 
 #include <errno.h>
diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 8bd1cef..6403630 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -306,6 +306,8 @@
  * of the vector itself.
  */
 #define AST_VECTOR_INSERT_AT(vec, idx, elem) ({ \
+	_Pragma("clang diagnostic push"); \
+	_Pragma("clang diagnostic ignored \"-Wtautological-compare\""); \
 	int res = 0; \
 	size_t __move; \
 	do { \
@@ -320,6 +322,7 @@
 		(vec)->elems[(idx)] = (elem); \
 		(vec)->current = ((idx) > (vec)->current ? (idx) : (vec)->current) + 1; \
 	} while (0); \
+	_Pragma("clang diagnostic pop"); \
 	res; \
 })
 
diff --git a/main/Makefile b/main/Makefile
index c724e20..cbcd3ab 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -63,8 +63,7 @@
 
 ifneq ($(findstring darwin,$(OSARCH)),)
   AST_LIBS+=-lresolv
-  ASTLINK=-mmacosx-version-min=10.6 -Wl,-undefined,dynamic_lookup -force_flat_namespace
-  ASTLINK+=/usr/lib/bundle1.o
+  ASTLINK=-Wl,-undefined,dynamic_lookup -force_flat_namespace
 else
 # These are used for all but Darwin
   ASTLINK+=-Wl,--export-dynamic
diff --git a/main/asterisk.c b/main/asterisk.c
index 450feb4..b3f86f1 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -714,12 +714,6 @@
 	ast_free(swdev);
 	return 1;
 }
-#elif defined(HAVE_SYSCTL) && !defined(HAVE_SYSINFO)
-static int swapmode(int *used, int *total)
-{
-	*used = *total = 0;
-	return 1;
-}
 #endif
 
 #if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL)
@@ -729,10 +723,10 @@
 	uint64_t physmem, freeram;
 #if defined(HAVE_SYSINFO) || defined(HAVE_SWAPCTL)
 	uint64_t freeswap = 0;
+	int totalswap = 0;
 #endif
 	int nprocs = 0;
 	long uptime = 0;
-	int totalswap = 0;
 #if defined(HAVE_SYSINFO)
 	struct sysinfo sys_info;
 #elif defined(HAVE_SYSCTL)
@@ -740,7 +734,10 @@
 	struct vmtotal vmtotal;
 	struct timeval	boottime;
 	time_t	now;
-	int mib[2], pagesize, usedswap = 0;
+	int mib[2], pagesize;
+#if defined(HAVE_SWAPCTL)
+	int usedswap = 0;
+#endif
 	size_t len;
 #endif
 
@@ -799,9 +796,11 @@
 	len = sizeof(vmtotal);
 	sysctl(mib, 2, &vmtotal, &len, NULL, 0);
 	freeram = (vmtotal.t_free << pageshift);
+#if defined(HAVE_SWAPCTL)
 	/* generate swap usage and totals */
 	swapmode(&usedswap, &totalswap);
 	freeswap = (totalswap - usedswap);
+#endif
 	/* grab number of processes */
 #if defined(__OpenBSD__)
 	mib[0] = CTL_KERN;
diff --git a/main/translate.c b/main/translate.c
index 02717c5..3d3e0be 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -1415,10 +1415,10 @@
 				beststeps = matrix_get(x, y)->multistep;
 			} else if (matrix_get(x, y)->table_cost == besttablecost
 					&& matrix_get(x, y)->multistep == beststeps) {
-				int gap_selected = abs(ast_format_get_sample_rate(best)
-					- ast_format_get_sample_rate(bestdst));
-				int gap_current = abs(ast_format_get_sample_rate(src)
-					- ast_format_get_sample_rate(dst));
+				int gap_selected = abs((int)(ast_format_get_sample_rate(best)
+					- ast_format_get_sample_rate(bestdst)));
+				int gap_current = abs((int)(ast_format_get_sample_rate(src)
+					- ast_format_get_sample_rate(dst)));
 
 				if (gap_current < gap_selected) {
 					/* better than what we have so far */
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index abd00ca..ca6cb83 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -1290,14 +1290,15 @@
 				struct ast_str *sql = ast_str_create(100);
 				char fieldtype[15];
 				PGresult *result;
+				int length;
 
 				if (requirements == RQ_CREATECHAR || type == RQ_CHAR) {
 					/* Size is minimum length; make it at least 50% greater,
 					 * just to be sure, because PostgreSQL doesn't support
 					 * resizing columns. */
-					snprintf(fieldtype, sizeof(fieldtype), "CHAR(%hhu)",
-						size < 15 ? size * 2 :
-						(size * 3 / 2 > 255) ? 255 : size * 3 / 2);
+					length = size < 15 ? size * 2 :
+						(size * 3 / 2 > 255) ? 255 : size * 3 / 2;
+					snprintf(fieldtype, sizeof(fieldtype), "CHAR(%d)", length);
 				} else if (type == RQ_INTEGER1 || type == RQ_UINTEGER1 || type == RQ_INTEGER2) {
 					snprintf(fieldtype, sizeof(fieldtype), "INT2");
 				} else if (type == RQ_UINTEGER2 || type == RQ_INTEGER3 || type == RQ_UINTEGER3 || type == RQ_INTEGER4) {
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index baaa40f..353b564 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -291,7 +291,7 @@
 /*! \brief Close function for websocket session */
 int AST_OPTIONAL_API_NAME(ast_websocket_close)(struct ast_websocket *session, uint16_t reason)
 {
-	char frame[4] = { 0, }; /* The header is 2 bytes and the reason code takes up another 2 bytes */
+	unsigned char frame[4] = { 0, }; /* The header is 2 bytes and the reason code takes up another 2 bytes */
 	int res;
 
 	if (session->close_sent) {

-- 
To view, visit https://gerrit.asterisk.org/7778
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3900881168c570c4177bf394caf33562e5c67f94
Gerrit-Change-Number: 7778
Gerrit-PatchSet: 1
Gerrit-Owner: David M. Lee <dlee at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171231/32c61a06/attachment-0001.html>


More information about the asterisk-code-review mailing list