[cig-commits] commit: Allow multiple spaces between horizontal viewport names to fix crash when too many entered, also limited to 16 viewports across window (for 1.4.1 patch)

Mercurial hg at geodynamics.org
Tue Mar 23 10:36:19 PDT 2010


changeset:   219:a26907a39f4f
branch:      1.4.x
user:        Owen Kaluza <Owen.Kaluza at sci.monash.edu.au>
date:        Fri Feb 19 12:33:15 2010 +1100
files:       Base/src/Window.c
description:
Allow multiple spaces between horizontal viewport names to fix crash when too many entered, also limited to 16 viewports across window (for 1.4.1 patch)


diff -r 4753fbbb25ef -r a26907a39f4f Base/src/Window.c
--- a/Base/src/Window.c	Thu Feb 18 11:50:38 2010 +1100
+++ b/Base/src/Window.c	Fri Feb 19 12:33:15 2010 +1100
@@ -745,8 +745,7 @@ lucViewportInfo* lucWindow_ConstructView
 	lucViewportInfo*        viewportInfoList        = Memory_Alloc_Array( lucViewportInfo, 1, "viewportInfoArray" );
 	lucViewportInfo*        currViewportInfo;
 	Dictionary*             dictionary              = Dictionary_GetDictionary( cf->componentDict, self->name );
-	Name                    viewportName;
-	char*                   bufferPtr;
+	Name                    viewportName[16];
 
 	*viewportCount = 0;
 	
@@ -762,11 +761,19 @@ lucViewportInfo* lucWindow_ConstructView
 		horizontalVP_String = StG_Strdup( Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, vertical_I ) ) );
 	
 		/* Find number of horizontal layers */
-		horizontalCount = 1;
-		charPtr = strpbrk( horizontalVP_String, breakChars );
+		horizontalCount = 0;
+		char* horizVPstr_ptr = horizontalVP_String;
+		charPtr = strtok( horizVPstr_ptr , breakChars );
 		while ( charPtr != NULL ) {
-			charPtr = strpbrk( charPtr + 1 , breakChars );
+			viewportName[horizontalCount] = StG_Strdup( charPtr );
 			horizontalCount++;
+			charPtr = strtok( NULL , breakChars );
+         if (horizontalCount == 16) {
+            /* Maximum 8 viewports across in single window */
+            if (charPtr != NULL)
+   			   Journal_Printf( lucError, "Error in func '%s' - too many viewports in window %s, maximum = 16 wide.\n", __func__, self->name);
+            break; 
+         }
 		}
 		
 		/* Sum up total number of viewports */
@@ -779,22 +786,18 @@ lucViewportInfo* lucWindow_ConstructView
 		viewportWidth = div( width, horizontalCount ).quot;
 
 		/* Read String to get colour map */
-		charPtr = strtok_r( horizontalVP_String, breakChars, &bufferPtr );
 		for ( horizontal_I = 0 ; horizontal_I < horizontalCount ; horizontal_I++ ) {
 			currViewportInfo = &viewportInfoList[ total_I ];
 
 			/* Find viewport */
-			viewportName = StG_Strdup( charPtr );
-			currViewportInfo->viewport = Stg_ComponentFactory_ConstructByName( cf, (Name)viewportName, lucViewport, True, data ) ;
-			Memory_Free( viewportName );
+			currViewportInfo->viewport = Stg_ComponentFactory_ConstructByName( cf, viewportName[horizontal_I], lucViewport, True, data ) ;
+			Memory_Free( viewportName[horizontal_I] );
 
 			/* Setup viewport dimensions */
 			currViewportInfo->startx = horizontal_I * viewportWidth;
 			currViewportInfo->starty = (self->verticalCount - 1 - vertical_I ) * viewportHeight;
 			currViewportInfo->width  = viewportWidth;
 			currViewportInfo->height = viewportHeight;
-
-			charPtr = strtok_r( NULL, breakChars, &bufferPtr );
 
 			total_I++;
 		}



More information about the CIG-COMMITS mailing list