From owner-freebsd-ports@FreeBSD.ORG Thu Sep 27 12:16:55 2012 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 241251065675 for ; Thu, 27 Sep 2012 12:16:55 +0000 (UTC) (envelope-from mexas@bristol.ac.uk) Received: from dirj.bris.ac.uk (dirj.bris.ac.uk [137.222.10.78]) by mx1.freebsd.org (Postfix) with ESMTP id D390C8FC15 for ; Thu, 27 Sep 2012 12:16:54 +0000 (UTC) Received: from irix.bris.ac.uk ([137.222.10.39] helo=ncs.bris.ac.uk) by dirj.bris.ac.uk with esmtp (Exim 4.72) (envelope-from ) id 1THD1D-0002sn-NE for freebsd-ports@freebsd.org; Thu, 27 Sep 2012 13:16:48 +0100 Received: from mech-cluster241.men.bris.ac.uk ([137.222.187.241]) by ncs.bris.ac.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1THD1D-0000qm-Ij for freebsd-ports@freebsd.org; Thu, 27 Sep 2012 13:16:39 +0100 Received: from mech-cluster241.men.bris.ac.uk (localhost [127.0.0.1]) by mech-cluster241.men.bris.ac.uk (8.14.5/8.14.5) with ESMTP id q8RCGdi4001140 for ; Thu, 27 Sep 2012 13:16:39 +0100 (BST) (envelope-from mexas@mech-cluster241.men.bris.ac.uk) Received: (from mexas@localhost) by mech-cluster241.men.bris.ac.uk (8.14.5/8.14.5/Submit) id q8RCGdWU001139 for freebsd-ports@freebsd.org; Thu, 27 Sep 2012 13:16:39 +0100 (BST) (envelope-from mexas) Date: Thu, 27 Sep 2012 13:16:39 +0100 (BST) From: Anton Shterenlikht Message-Id: <201209271216.q8RCGdWU001139@mech-cluster241.men.bris.ac.uk> To: freebsd-ports@freebsd.org X-Spam-Score: -3.0 X-Spam-Level: --- Subject: clang dangling else help X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: mexas@bristol.ac.uk List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Sep 2012 12:16:55 -0000 I'm not great with C. Building my port with clang I get this warning (gcc doesn't pick this up): x11.c:1543:5: warning: add explicit braces to avoid dangling else [-Wdangling-else] else if (actual_type != None) ^ 1 warning generated. I think I understand what's going on, but wanted somebody to double check. This is the relevant fragment: 1511 static void freePrevious(dpy, w) 1512 Display *dpy; 1513 Window w; 1514 { 1515 Pixmap *pm; 1516 Atom actual_type; 1517 int format; 1518 unsigned long nitems; 1519 unsigned long bytes_after; 1520 1521 /* intern the property name */ 1522 Atom atom = XInternAtom(dpy, RETAIN_PROP_NAME, 0); 1523 1524 /* look for existing resource allocation */ 1525 if ((XGetWindowProperty(dpy, w, atom, 0, 1, 1 /*delete*/, 1526 AnyPropertyType, &actual_type, 1527 &format, &nitems, &bytes_after, 1528 (unsigned char **) &pm) == Success) && 1529 (nitems == 1)) 1530 if ((actual_type == XA_PIXMAP) && (format == 32) && 1531 (nitems == 1) && (bytes_after == 0)) 1532 { 1533 /* blast it away, but first provide new X error handler in case 1534 * the client that installed the RETAIN_PROP_NAME (_XSETROOT_ID) 1535 * property on the root window has already terminated 1536 */ 1537 orig_error_handler = XSetErrorHandler(xkill_handler); 1538 XKillClient(dpy, (XID) *pm); 1539 XSync(dpy, False); 1540 XSetErrorHandler(orig_error_handler); 1541 XFree((void *) pm); 1542 } 1543 else if (actual_type != None) 1544 { 1545 fprintf(stderr, 1546 "%s: warning: invalid format encountered for property %s\n", 1547 RETAIN_PROP_NAME, progname); 1548 } 1549 } I think, to preserve the logic, this should be changed to: 1511 static void freePrevious(dpy, w) 1512 Display *dpy; 1513 Window w; 1514 { 1515 Pixmap *pm; 1516 Atom actual_type; 1517 int format; 1518 unsigned long nitems; 1519 unsigned long bytes_after; 1520 1521 /* intern the property name */ 1522 Atom atom = XInternAtom(dpy, RETAIN_PROP_NAME, 0); 1523 1524 /* look for existing resource allocation */ 1525 if ((XGetWindowProperty(dpy, w, atom, 0, 1, 1 /*delete*/, 1526 AnyPropertyType, &actual_type, 1527 &format, &nitems, &bytes_after, 1528 (unsigned char **) &pm) == Success) && 1529 (nitems == 1)) { 1530 if ((actual_type == XA_PIXMAP) && (format == 32) && 1531 (nitems == 1) && (bytes_after == 0)) 1532 { 1533 /* blast it away, but first provide new X error handler in case 1534 * the client that installed the RETAIN_PROP_NAME (_XSETROOT_ID) 1535 * property on the root window has already terminated 1536 */ 1537 orig_error_handler = XSetErrorHandler(xkill_handler); 1538 XKillClient(dpy, (XID) *pm); 1539 XSync(dpy, False); 1540 XSetErrorHandler(orig_error_handler); 1541 XFree((void *) pm); 1542 } 1543 else if (actual_type != None) 1544 { 1545 fprintf(stderr, 1546 "%s: warning: invalid format encountered for property %s\n", 1547 RETAIN_PROP_NAME, progname); 1548 } } 1549 } I guess it's impossible to say for sure, without knowing the whole of the code, but, judging by the identation, this was probably the intended logic. Can somebody confirm this. Thanks Anton