@@ -40,8 +40,8 @@ static int get_reclass_table(FILE *, struct Reclass *);
4040 * \return 0 if it is not
4141 * \return -1 if there was a problem reading the raster header
4242 */
43- int Rast_is_reclass (const char * name , const char * mapset , char * rname ,
44- char * rmapset )
43+ int Rast_is_reclass (const char * name , const char * mapset , char rname [ GNAME_MAX ] ,
44+ char rmapset [ GMAPSET_MAX ] )
4545{
4646 FILE * fd ;
4747 int type ;
@@ -142,13 +142,15 @@ int Rast_get_reclass(const char *name, const char *mapset,
142142{
143143 FILE * fd ;
144144 int stat ;
145+ char rname [GNAME_MAX ] = {0 }, rmapset [GMAPSET_MAX ] = {0 };
146+ char * tmp_name = rname , * tmp_mapset = rmapset ;
145147
146148 fd = fopen_cellhd_old (name , mapset );
147149 if (fd == NULL )
148150 return -1 ;
149- reclass -> name = NULL ;
150- reclass -> mapset = NULL ;
151- reclass -> type = reclass_type ( fd , & reclass -> name , & reclass -> mapset );
151+ reclass -> type = reclass_type ( fd , & tmp_name , & tmp_mapset ) ;
152+ reclass -> name = G_store ( tmp_name ) ;
153+ reclass -> mapset = G_store ( tmp_mapset );
152154 if (reclass -> type <= 0 ) {
153155 fclose (fd );
154156 return reclass -> type ;
@@ -224,22 +226,16 @@ static int reclass_type(FILE *fd, char **rname, char **rmapset)
224226 return -1 ;
225227 if (sscanf (buf , "%[^:]:%s" , label , arg ) != 2 )
226228 return -1 ;
227- if (strncmp (label , "maps" , 4 ) == 0 ) {
228- if (* rmapset )
229- strcpy (* rmapset , arg );
230- else
231- * rmapset = G_store (arg );
229+ if (strncmp (label , "maps" , 4 ) == 0 && * rmapset ) {
230+ G_strlcpy (* rmapset , arg , GMAPSET_MAX );
232231 }
233- else if (strncmp (label , "name" , 4 ) == 0 ) {
234- if (* rname )
235- strcpy (* rname , arg );
236- else
237- * rname = G_store (arg );
232+ else if (strncmp (label , "name" , 4 ) == 0 && * rname ) {
233+ G_strlcpy (* rname , arg , GNAME_MAX );
238234 }
239235 else
240236 return -1 ;
241237 }
242- if (* * rmapset && * * rname )
238+ if (( * rmapset && * * rmapset ) || ( * rname && * * rname ) )
243239 return type ;
244240 else
245241 return -1 ;
0 commit comments