[brlcad-commits] CVS: brlcad/src/conv/patch patch-g.c, 1.14, 1.15 patch-g.h, 1.5, 1.6 rpatch.c, 1.9
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: Sean M. <br...@us...> - 2007-10-14 22:16:01
|
Update of /cvsroot/brlcad/brlcad/src/conv/patch In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27964/src/conv/patch Modified Files: patch-g.c patch-g.h rpatch.c Log Message: more level 4 flawfinder issues. mostly string length clampages. Index: patch-g.c =================================================================== RCS file: /cvsroot/brlcad/brlcad/src/conv/patch/patch-g.c,v retrieving revision 1.14 retrieving revision 1.15 diff -w -u -r1.14 -r1.15 --- patch-g.c 15 Sep 2007 16:23:05 -0000 1.14 +++ patch-g.c 14 Oct 2007 22:15:55 -0000 1.15 @@ -136,7 +136,7 @@ int i; int done; int stop,num; - char name[17]; + char name[NAMESIZE+1]; BU_LIST_INIT( &head.l); BU_LIST_INIT( &heada.l); @@ -353,7 +353,7 @@ while (done != 0){ if( (stop=fscanf( gfp, "%4d", &num )) == 1 ){ - fscanf( gfp, "%s %s", nm[num].ug, nm[num].lg ); + fscanf( gfp, "%16s %16s", nm[num].ug, nm[num].lg ); /* NAMESIZE */ while( (fgetc( gfp )) != '\n' ) ; } @@ -530,7 +530,7 @@ } if( done ) { - sprintf(name,"%dxxx_series",in[0].cc/1000); + snprintf(name, NAMESIZE, "%dxxx_series",in[0].cc/1000); mk_lcomb(outfp,name,&headd,0,"","",rgb,0); (void) mk_addmember(name,&heade.l,NULL, WMOP_UNION); } @@ -547,7 +547,7 @@ } /* end "processing" if */ } - sprintf(name,"%s",top_level); + snprintf(name, NAMESIZE, "%s",top_level); mk_lcomb(outfp,name,&heade,0,"","",0,0); if( BU_LIST_NON_EMPTY( &headf.l )) { @@ -755,7 +755,7 @@ proc_sname(char shflg, char mrflg, int cnt, char ctflg) { char side; - static char new_name[17]; + static char new_name[NAMESIZE+1]; /* shflg == identifies shape process which called this function * mrflg == indicates called by "as-modeled" pass or mirrored pass @@ -1006,7 +1006,7 @@ if( arb6 && plate_mode ) { fastf_t pts[24]; - char tmp_name[16]; + char tmp_name[NAMESIZE]; struct wmember tmp_head, mir_head; BU_LIST_INIT( &tmp_head.l ); @@ -1045,14 +1045,14 @@ VJOIN1( &pts[2*3], &pts[1*3], thickness, norm ) VJOIN1( &pts[6*3], &pts[4*3], thickness, norm ) VMOVE( &pts[7*3], &pts[6*3] ); - sprintf( tmp_name, "%s_%d", name, k ); + snprintf( tmp_name, NAMESIZE, "%s_%d", name, k ); mk_arb8( outfp, tmp_name, pts ); mk_addmember( tmp_name, &tmp_head.l, NULL, WMOP_UNION ); if( mirror_name[0] ) { for( i=0 ; i<8 ; i++ ) pts[i*3 + 1] = -pts[i*3 + 1]; - sprintf( tmp_name, "%s_%dm", name, k ); + snprintf( tmp_name, NAMESIZE, "%s_%dm", name, k ); mk_arb8( outfp, tmp_name, pts ); mk_addmember( tmp_name, &mir_head.l, NULL, WMOP_UNION ); } @@ -1415,9 +1415,9 @@ if( debug > 4 ) { - char tmp_name[17]; + char tmp_name[NAMESIZE+1]; - sprintf( tmp_name , "out.%s" , name ); + snprintf( tmp_name , NAMESIZE, "out.%s" , name ); mk_nmg( outfp , tmp_name , m ); } @@ -1542,14 +1542,11 @@ if( !nmg_ks( is ) ) { /* debugging: write an NMG of the outer shell named "name.BAD" */ - char *bad; + char bad[NAMESIZE+5]; - bad = (char *)bu_malloc( strlen( name ) + 5 , "build_solid: Name for Bad solid" ); - strcpy( bad , name ); - strcat( bad , ".BAD" ); + snprintf(bad, NAMESIZE+5, "%s.BAD", name); mk_nmg( outfp , bad , m ); bu_log( "BAD shell written as %s\n" , bad ); - bu_free( (char *)bad , "build_solid: Name for Bad solid" ); } nmg_km( m ); bu_free( (char *)flags , "build_solid: flags" ); @@ -1566,9 +1563,9 @@ if( debug > 4 ) { - char tmp_name[32]; + char tmp_name[NAMESIZE+6]; - sprintf( tmp_name , "open.%s" , name ); + snprintf( tmp_name , NAMESIZE+6, "open.%s" , name ); mk_nmg( outfp , tmp_name , m ); } @@ -1580,14 +1577,11 @@ if( nmg_open_shells_connect( s , is , (const long **)copy_tbl , tol ) ) { /* debugging: write an NMG of the outer shell named "name.BAD" */ - char *bad; + char bad[NAMESIZE+5]; - bad = (char *)bu_malloc( strlen( name ) + 5 , "build_solid: Name for Bad solid" ); - strcpy( bad , name ); - strcat( bad , ".BAD" ); + snprintf(bad, NAMESIZE+5, "%s.BAD", name); mk_nmg( outfp , bad , m ); bu_log( "BAD shell written as %s\n" , bad ); - bu_free( (char *)bad , "build_solid: Name for Bad solid" ); nmg_km( m ); bu_free( (char *)flags , "Build_solid: flags" ); bu_free( (char *)copy_tbl , "Build_solid: copy_tbl" ); @@ -1699,7 +1693,7 @@ void proc_region(char *name1) { - char tmpname[24]; + char tmpname[NAMESIZE*2]; int chkroot; int i; int cc; @@ -1711,7 +1705,7 @@ if( BU_LIST_IS_EMPTY( &head.l ) ) return; - strcpy( tmpname , name1 ); + strncpy( tmpname , name1, NAMESIZE*2 ); chkroot = 0; while( tmpname[chkroot++] != '.' ); @@ -1731,12 +1725,12 @@ if( cc != in[0].cc ) { mir_count++; - sprintf(cname,"%s.r%.2d",tmpname,mir_count); + snprintf(cname, NAMESIZE, "%s.r%.2d",tmpname,mir_count); } else { reg_count++; - sprintf(cname,"%s.r%.2d",tmpname,reg_count); + snprintf(cname, NAMESIZE, "%s.r%.2d",tmpname,reg_count); } @@ -1770,7 +1764,7 @@ static int count=0; static int mir_count=0; static int last_cc=0; - char name[17],mirror_name[17]; + char name[NAMESIZE+1],mirror_name[NAMESIZE+1]; plane_t pl; point_t last; @@ -1844,14 +1838,14 @@ shflg = 'f'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name,proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); count++; if(in[0].mirror != 0) { mrflg = 'y'; - strcpy( mirror_name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( mirror_name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); mir_count++; } else @@ -2043,7 +2037,7 @@ static int last_cc=0; int cpts; char shflg,mrflg,ctflg; - char name[17],mirror_name[17]; + char name[NAMESIZE+1],mirror_name[NAMESIZE+1]; plane_t pl; point_t last; @@ -2178,12 +2172,12 @@ shflg = 't'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); if( in[0].mirror != 0 ) { mrflg = 'y'; - strcpy( mirror_name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( mirror_name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); } else mirror_name[0] = '\0'; @@ -2239,7 +2233,7 @@ static int mir_count=0; static int last_cc=0; char shflg='\0',mrflg,ctflg; - char name[17]; + char name[NAMESIZE+1]; int ret = 0; static struct bn_tol *tols = &tol; @@ -2272,7 +2266,7 @@ shflg = 'w'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); /* make solids */ @@ -2288,7 +2282,7 @@ fastf_t join_scale = 1.0/8.0; ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count,ctflg), NAMESIZE ); /* Create planes for arb6. Planes will be formed with normal pointing inward for creation of inner arb6 */ @@ -2386,7 +2380,7 @@ mrflg = 'y'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); mk_arb8( outfp, name, &pt8[0][X] ); mir_count++; @@ -2399,7 +2393,7 @@ fastf_t join_scale = 1.0/8.0; ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count,ctflg), NAMESIZE ); /* Create planes for arb6. Planes will be formed with normal pointing inward for creation of inner arb6 */ @@ -2487,7 +2481,7 @@ static int count=0; static int mir_count=0; static int last_cc=0; - char name[17]; + char name[NAMESIZE+1]; if( in[cnt-1].cc != last_cc ) { @@ -2502,7 +2496,7 @@ shflg = 's'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); count++; VSET(center,in[i].x,in[i].y,in[i].z); @@ -2523,7 +2517,7 @@ /* name inside solid */ ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count,ctflg), NAMESIZE ); /* make inside solid */ @@ -2557,7 +2551,7 @@ mrflg = 'y'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); VSET(center,in[i].x,-in[i].y,in[i].z); @@ -2573,7 +2567,7 @@ if (in[i].surf_mode== '-'){ ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,mir_count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count,ctflg), NAMESIZE ); if( (rad = in[i+1].x - in[i].rsurf_thick) > 0.0 ) { mk_sph(outfp,name,center,rad); @@ -2615,7 +2609,7 @@ static int count=0; static int mir_count=0; static int last_cc=0; - char name[17]; + char name[NAMESIZE+1]; if( in[cnt-1].cc != last_cc ) { @@ -2644,7 +2638,7 @@ shflg = 'b'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); /* make solid */ @@ -2656,7 +2650,7 @@ if( in[k].surf_mode == '-' ){ ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count,ctflg), NAMESIZE ); valid = 1; len = MAGNITUDE( ab ); @@ -2737,7 +2731,7 @@ mrflg = 'y'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); mk_arb8( outfp, name, &pt8[0][X] ); mir_count++; @@ -2747,7 +2741,7 @@ if( in[k].surf_mode == '-' ){ ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); valid = 1; len = MAGNITUDE( ab ); @@ -2824,14 +2818,14 @@ fastf_t magh3, magh4; int end_code; struct wmember donut_head; - char name[17]; + char name[NAMESIZE+1]; char shflg,mrflg,ctflg; int count=0; int make_basic_solids; - char scratch_name1[17]; - char scratch_name2[17]; - char scratch_name3[17]; - char scratch_name4[17]; + char scratch_name1[NAMESIZE+1]; + char scratch_name2[NAMESIZE+1]; + char scratch_name3[NAMESIZE+1]; + char scratch_name4[NAMESIZE+1]; for( k=0 ; k<cnt-1 ; k += 6 ) /* for each donut */ { @@ -2912,7 +2906,7 @@ shflg = 'd'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); count++; BU_LIST_INIT( &donut_head.l ); @@ -3062,10 +3056,10 @@ } else /* plate mode */ { - char scratch_name1_in[17]; - char scratch_name2_in[17]; - char scratch_name3_in[17]; - char scratch_name4_in[17]; + char scratch_name1_in[NAMESIZE+1]; + char scratch_name2_in[NAMESIZE+1]; + char scratch_name3_in[NAMESIZE+1]; + char scratch_name4_in[NAMESIZE+1]; if( end_code == 0 || end_code == 1 || end_code == 2 || end_code ==3 ) { @@ -3213,7 +3207,7 @@ static int count=0; static int mir_count=0; static int last_cc=0; - char name[17]; + char name[NAMESIZE+1]; if( in[cnt-1].cc != last_cc ) { @@ -3238,7 +3232,7 @@ shflg = 'c'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); count++; @@ -3278,7 +3272,7 @@ fastf_t rad1_tmp,rad2_tmp; ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count,ctflg), NAMESIZE ); rad1 = in[k+2].x; rad2 = in[k+2].y; @@ -3546,7 +3540,7 @@ mrflg = 'y'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); mir_count++; if(!((in[k].x==in[k+1].x)&&(in[k].y==in[k+1].y)&&(in[k].z==in[k+1].z))){ @@ -3578,7 +3572,7 @@ fastf_t rad1_tmp,rad2_tmp; ctflg = 'y'; - strcpy( name , proc_sname (shflg,mrflg,mir_count,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count,ctflg), NAMESIZE ); rad1 = in[k+2].x; rad2 = in[k+2].y; @@ -3852,7 +3846,7 @@ static int count=0; static int mir_count=0; static int last_cc=0; - char name[17]; + char name[NAMESIZE+1]; if( in[cnt-1].cc != last_cc ) { @@ -3920,7 +3914,7 @@ shflg = 'r'; mrflg = 'n'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,count+1,ctflg), NAMESIZE ); /* make solids */ count++; @@ -3966,7 +3960,7 @@ mrflg = 'y'; ctflg = 'n'; - strcpy( name , proc_sname (shflg,mrflg,mir_count+1,ctflg) ); + strncpy( name, proc_sname (shflg,mrflg,mir_count+1,ctflg), NAMESIZE ); /* make solids */ mir_count++; @@ -4053,7 +4047,7 @@ void proc_label(char *labelfile) { - char gname[16+1], mgname[16+1]; /* group, mirrored group names */ + char gname[NAMESIZE+1], mgname[NAMESIZE+1]; /* group, mirrored group names */ static int cur_series = -1; if( cur_series == -1 ) { /* first time */ @@ -4066,12 +4060,12 @@ if( cur_series == (in[0].cc / 1000)) { if( labelfile != NULL ) { - sprintf(gname,"%s", nm[in[0].cc].ug ); - sprintf(mgname,"%s", nm[in[0].cc + in[0].mirror].ug ); + snprintf(gname, NAMESIZE, "%s", nm[in[0].cc].ug ); + snprintf(mgname, NAMESIZE, "%s", nm[in[0].cc + in[0].mirror].ug); } else { - sprintf(gname,"#%.4d",in[0].cc); - sprintf(mgname,"#%.4d",(in[0].cc + in[0].mirror)); + snprintf(gname, NAMESIZE, "#%.4d",in[0].cc); + snprintf(mgname, NAMESIZE, "#%.4d",(in[0].cc + in[0].mirror)); } if( BU_LIST_NON_EMPTY( &heada.l ) ) { @@ -4291,7 +4285,7 @@ mk_cyladdmember(char *name1, struct wmember *head, struct subtract_list *slist, int mirflag) { - char tmpname[16]; + char tmpname[NAMESIZE]; int cc,solnum; struct subtract_list *hold; Index: patch-g.h =================================================================== RCS file: /cvsroot/brlcad/brlcad/src/conv/patch/patch-g.h,v retrieving revision 1.5 retrieving revision 1.6 diff -w -u -r1.5 -r1.6 --- patch-g.h 27 Jan 2007 01:41:33 -0000 1.5 +++ patch-g.h 14 Oct 2007 22:15:55 -0000 1.6 @@ -59,10 +59,11 @@ }; +#define NAMESIZE 16 struct names{ - char ug[16]; - char lg[16]; + char ug[NAMESIZE]; + char lg[NAMESIZE]; int eqlos, matcode; @@ -88,9 +89,9 @@ double conv_mm2in; fastf_t third = 0.333333333; -/* char name[17]; */ -char cname[17]; -char tname[17]; +/* char name[NAMESIZE+1]; */ +char cname[NAMESIZE+1]; +char tname[NAMESIZE+1]; char surf[2]; char thick[3]; char space[2]; Index: rpatch.c =================================================================== RCS file: /cvsroot/brlcad/brlcad/src/conv/patch/rpatch.c,v retrieving revision 1.9 retrieving revision 1.10 diff -w -u -r1.9 -r1.10 --- rpatch.c 15 Sep 2007 16:23:05 -0000 1.9 +++ rpatch.c 14 Oct 2007 22:15:55 -0000 1.10 @@ -44,7 +44,7 @@ #define MAXLINELEN 256 -static char *usage="Usage:\n\trpatch [-D] [-3] < fastgen_input_file > file.rp\n\ +static const char *usage="Usage:\n\trpatch [-D] [-3] < fastgen_input_file > file.rp\n\ where -D means that type 3 components are donuts (rather than triangles)\n\ and -3 indicates that the input is in FASTGEN3 format\n"; |