From: <ai...@us...> - 2009-07-10 06:21:21
|
Revision: 10135 http://plplot.svn.sourceforge.net/plplot/?rev=10135&view=rev Author: airwin Date: 2009-07-10 06:21:20 +0000 (Fri, 10 Jul 2009) Log Message: ----------- Call plscmap0n from within plspal0 to allocate sufficient cmap0 colour space to accomodate the specified number of colours. Implement some additional range checking within plspal[01]. Most of this checking is routine, but demand at least 16 cmap0 colours to make it impossible to starve cmap0 colours with the plscmap0n call referred to above. Modified Paths: -------------- trunk/src/plctrl.c Modified: trunk/src/plctrl.c =================================================================== --- trunk/src/plctrl.c 2009-07-10 01:54:08 UTC (rev 10134) +++ trunk/src/plctrl.c 2009-07-10 06:21:20 UTC (rev 10135) @@ -1232,12 +1232,13 @@ plwarn(msgbuf); return; } - if (fscanf(fp, "%d\n", &number_colors) != 1) { + if (fscanf(fp, "%d\n", &number_colors) != 1 || number_colors < 16) { snprintf(msgbuf,1024,"Unrecognized cmap0 header\n"); plwarn(msgbuf); fclose(fp); return; } + plscmap0n(number_colors); for(i=0;i<number_colors;i++){ fgets(color_info, 30, fp); color_info[strlen(color_info)-1] = '\0'; /* remove return character */ @@ -1255,6 +1256,11 @@ plwarn(msgbuf); break; } + if(a < 0. || a > 1.) { + snprintf(msgbuf,1024,"Unrecognized cmap0 format %s\n", color_info); + plwarn(msgbuf); + break; + } c_plscol0a(i, r, g, b, (PLFLT) a); } else{ @@ -1315,7 +1321,7 @@ fgets(color_info, 160, fp); } - if (sscanf(color_info, "%d\n", &number_colors) != 1) { + if (sscanf(color_info, "%d\n", &number_colors) != 1 || number_colors < 2) { snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info); plwarn(msgbuf); fclose(fp); @@ -1351,6 +1357,12 @@ b[i] = (PLFLT)b_i/255.; a[i] = 1.0; pos[i] = 0.01*(PLFLT)pos_i; + if(pos[i] < 0. || pos[i] > 1.) { + snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info); + plwarn(msgbuf); + err = 1; + break; + } if(return_sscanf == 5) { /* Next to oldest tk format with rev specified. */ rev[i] = (PLBOOL)rev_i; @@ -1372,8 +1384,21 @@ err = 1; break; } - /* For rgb case of new format colours are already normalized from - 0., to 1. */ + /* Check that all rgba and pos data within range from 0. to + 1. except for the hls colour space case where the first + coordinate is checked within range from 0. to 360.*/ + if((rgb && (r_d < 0. || r_d > 1.)) || + (!rgb && (r_d < 0. || r_d > 360.)) || + g_d < 0. || g_d > 1. || + b_d < 0. || b_d > 1. || + a_d < 0. || a_d > 1. || + pos_d < 0. || pos_d > 1.) { + snprintf(msgbuf,1024,"Unrecognized cmap1 format %s\n", color_info); + plwarn(msgbuf); + err = 1; + break; + } + r[i] = (PLFLT)r_d; g[i] = (PLFLT)g_d; b[i] = (PLFLT)b_d; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |