Skip to content

Commit bbf646f

Browse files
committed
lib/raster: test reclass
1 parent 8cc8db2 commit bbf646f

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

include/grass/defs/raster.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ int Rast_option_to_interp_type(const struct Option *);
400400
/* mask_info.c */
401401
char *Rast_mask_info(void);
402402
char *Rast_mask_name(void);
403-
bool Rast_mask_status(char *, char *, bool *, char *, char *);
403+
bool Rast_mask_status(char *, char *, bool *, char[GNAME_MAX],
404+
char[GMAPSET_MAX]);
404405
int Rast__mask_info(char *, char *);
405406
bool Rast_mask_is_present(void);
406407
int Rast_disable_omp_on_mask(int);
@@ -558,7 +559,8 @@ bool Rast_legal_semantic_label(const char *);
558559
int Rast_map_to_img_str(char *, int, unsigned char *);
559560

560561
/* reclass.c */
561-
int Rast_is_reclass(const char *, const char *, char *, char *);
562+
int Rast_is_reclass(const char *, const char *, char[GNAME_MAX],
563+
char[GMAPSET_MAX]);
562564
int Rast_is_reclassed_to(const char *, const char *, int *, char ***);
563565
int Rast_get_reclass(const char *, const char *, struct Reclass *);
564566
void Rast_free_reclass(struct Reclass *);

lib/raster/mask_info.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ static bool Rast__get_present_mask(char *name, char *mapset)
136136
* @return true if mask is present, false otherwise
137137
*/
138138
bool Rast_mask_status(char *name, char *mapset, bool *is_mask_reclass,
139-
char *reclass_name, char *reclass_mapset)
139+
char reclass_name[GNAME_MAX],
140+
char reclass_mapset[GMAPSET_MAX])
140141
{
141142
bool present = Rast__get_present_mask(name, mapset);
142143

lib/raster/reclass.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)