[asterisk-commits] mjordan: branch 13 r433718 - in /branches/13: ./ main/stdtime/localtime.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Mar 29 20:52:50 CDT 2015


Author: mjordan
Date: Sun Mar 29 20:52:47 2015
New Revision: 433718

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433718
Log:
clang compiler warnings: Fix warning for -Wgnu-variable-sized-type-not-at-end

This patch fixes a warning caught by clang, wherein a variable sized struct is
not located at the end of a struct. While the code in question actually
expected this, this is a good warning to watch for. Hence, this patch refactors
the code in question to not have two variable length elements in the same
struct.

Review: https://reviewboard.asterisk.org/r/4530/

ASTERISK-24917
Reported by: dkdegroot
patches:
  rb4530.patch submitted by dkdegroot (License 6600)
........

Merged revisions 433717 from http://svn.asterisk.org/svn/asterisk/branches/11

Modified:
    branches/13/   (props changed)
    branches/13/main/stdtime/localtime.c

Propchange: branches/13/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Modified: branches/13/main/stdtime/localtime.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/stdtime/localtime.c?view=diff&rev=433718&r1=433717&r2=433718
==============================================================================
--- branches/13/main/stdtime/localtime.c (original)
+++ branches/13/main/stdtime/localtime.c Sun Mar 29 20:52:47 2015
@@ -354,10 +354,9 @@
 
 static void *inotify_daemon(void *data)
 {
-	struct {
-		struct inotify_event iev;
-		char name[FILENAME_MAX + 1];
-	} buf;
+	/* inotify_event is dynamically sized */
+	struct inotify_event *iev;
+	size_t real_sizeof_iev = sizeof(*iev) + FILENAME_MAX + 1;
 	ssize_t res;
 	struct state *cur;
 
@@ -372,14 +371,15 @@
 		inotify_thread = AST_PTHREADT_NULL;
 		return NULL;
 	}
+	iev = ast_alloca(real_sizeof_iev);
 
 	common_startup();
 
 	for (;/*ever*/;) {
 		/* This read should block, most of the time. */
-		if ((res = read(inotify_fd, &buf, sizeof(buf))) < sizeof(buf.iev) && res > 0) {
+		if ((res = read(inotify_fd, &iev, real_sizeof_iev)) < sizeof(*iev) && res > 0) {
 			/* This should never happen */
-			ast_log(LOG_ERROR, "Inotify read less than a full event (%zd < %zu)?!!\n", res, sizeof(buf.iev));
+			ast_log(LOG_ERROR, "Inotify read less than a full event (%zd < %zu)?!!\n", res, sizeof(*iev));
 			break;
 		} else if (res < 0) {
 			if (errno == EINTR || errno == EAGAIN) {
@@ -395,7 +395,7 @@
 		}
 		AST_LIST_LOCK(&zonelist);
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&zonelist, cur, list) {
-			if (cur->wd[0] == buf.iev.wd || cur->wd[1] == buf.iev.wd) {
+			if (cur->wd[0] == iev->wd || cur->wd[1] == iev->wd) {
 				AST_LIST_REMOVE_CURRENT(list);
 				sstate_free(cur);
 				break;




More information about the asterisk-commits mailing list