[PATCH 05/12] dmx: attempt to untangle nested loops using same index variable

Alan Coopersmith alan.coopersmith at oracle.com
Wed Dec 17 21:06:29 PST 2014


This doesn't just make gcc sad, it makes my brain sad.

Change from:
    for (i = 0; i < dmxNumScreens; i++) {
        int i;
        for (i = 0; i < nconfigs; i++) {
            for (j = 0; j < dmxScreen->beNumVisuals; j++) {

to the easier to follow:
    for (i = 0; i < dmxNumScreens; i++) {
        for (j = 0; j < nconfigs; j++) {
            for (k = 0; k < dmxScreen->beNumVisuals; k++) {

Gets rid of gcc 4.8 warning:

dmxinit.c: In function ‘InitOutput’:
dmxinit.c:765:17: warning: declaration of ‘i’ shadows a previous local [-Wshadow]
             int i;
                 ^
dmxinit.c:608:9: warning: shadowed declaration is here [-Wshadow]
     int i;
         ^

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 hw/dmx/dmxinit.c |   30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c
index 37961b8..025dc86 100644
--- a/hw/dmx/dmxinit.c
+++ b/hw/dmx/dmxinit.c
@@ -762,7 +762,6 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
             dmxGlxVisualPrivate **configprivs = NULL;
             int nconfigs = 0;
             int (*oldErrorHandler) (Display *, XErrorEvent *);
-            int i;
 
             /* Catch errors if when using an older GLX w/o FBconfigs */
             oldErrorHandler = XSetErrorHandler(dmxNOPErrorHandler);
@@ -797,28 +796,29 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
             configprivs = malloc(nconfigs * sizeof(dmxGlxVisualPrivate *));
 
             if (configs != NULL && configprivs != NULL) {
+                int j;
 
                 /* Initialize our private info for each visual
                  * (currently only x_visual_depth and x_visual_class)
                  */
-                for (i = 0; i < nconfigs; i++) {
+                for (j = 0; j < nconfigs; j++) {
 
-                    configprivs[i] = (dmxGlxVisualPrivate *)
+                    configprivs[j] = (dmxGlxVisualPrivate *)
                         malloc(sizeof(dmxGlxVisualPrivate));
-                    configprivs[i]->x_visual_depth = 0;
-                    configprivs[i]->x_visual_class = 0;
+                    configprivs[j]->x_visual_depth = 0;
+                    configprivs[j]->x_visual_class = 0;
 
                     /* Find the visual depth */
-                    if (configs[i].vid > 0) {
-                        int j;
-
-                        for (j = 0; j < dmxScreen->beNumVisuals; j++) {
-                            if (dmxScreen->beVisuals[j].visualid ==
-                                configs[i].vid) {
-                                configprivs[i]->x_visual_depth =
-                                    dmxScreen->beVisuals[j].depth;
-                                configprivs[i]->x_visual_class =
-                                    dmxScreen->beVisuals[j].class;
+                    if (configs[j].vid > 0) {
+                        int k;
+
+                        for (k = 0; k < dmxScreen->beNumVisuals; k++) {
+                            if (dmxScreen->beVisuals[k].visualid ==
+                                configs[j].vid) {
+                                configprivs[j]->x_visual_depth =
+                                    dmxScreen->beVisuals[k].depth;
+                                configprivs[j]->x_visual_class =
+                                    dmxScreen->beVisuals[k].class;
                                 break;
                             }
                         }
-- 
1.7.9.2



More information about the xorg-devel mailing list