fix warning: array subscript is above array bounds
authorBen Noordhuis <info@bnoordhuis.nl>
Sat, 17 Mar 2012 21:58:48 +0000 (22:58 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Sun, 18 Mar 2012 01:17:09 +0000 (02:17 +0100)
Simplify and flatten the code while we're at it.

radiant/brushscript.cpp

index 359fd29996c755ba9e04c09428fb4cf886595b9d..d056b56b52c24a6f53db3aaa1252af9cba4f2667 100644 (file)
@@ -426,42 +426,28 @@ void Input( char*& pBuffer ){
        const char *fields[5] = { "", "", "", "", "" };
        float values[5];
 
-       for ( int n = 0; n < g_nVariableCount; n++ )
+       for ( int n = 0; n < 5 && n < g_nVariableCount; n++ )
        {
                if ( g_Variables[n].m_strInput.GetLength() > 0 ) {
                        bGo = true;
-                       if ( n < 5 ) {
-                               switch ( n )
-                               {
-                               case 0: fields[1] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 1: fields[2] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 2: fields[3] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 3: fields[4] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 4: fields[5] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               }
-                       }
+                       fields[n] = g_Variables[n].m_strInput.GetBuffer();
                }
        }
 
-       if ( bGo ) {
-               if ( DoBSInputDlg( fields, values ) == IDOK ) {
-                       for ( int n = 0; n < g_nVariableCount; n++ )
-                       {
-                               if ( g_Variables[n].m_strInput.GetLength() > 0 ) {
-                                       if ( n < 5 ) {
-                                               switch ( n )
-                                               {
-                                               case 0: g_Variables[n].m_fValue = values[1]; break;
-                                               case 1: g_Variables[n].m_fValue = values[2]; break;
-                                               case 2: g_Variables[n].m_fValue = values[3]; break;
-                                               case 3: g_Variables[n].m_fValue = values[4]; break;
-                                               case 4: g_Variables[n].m_fValue = values[5]; break;
-                                               }
-                                       }
-                               }
-                       }
+       if ( !bGo ) {
+               return;
+       }
+
+       if ( DoBSInputDlg( fields, values ) != IDOK ) {
+               g_bKeepGoing = false;
+               return;
+       }
+
+       for ( int n = 0; n < 5 && n < g_nVariableCount; n++ )
+       {
+               if ( g_Variables[n].m_strInput.GetLength() > 0 ) {
+                       g_Variables[n].m_fValue = values[n];
                }
-               else{ g_bKeepGoing = false; }
        }
 }