mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Mosaic: don't duplicate the description being validated
Mosaic's validate_desc() doesn't write to the description string, so it has no need to make a copy of it. And if it doesn't copy it, it can't leak the copy.
This commit is contained in:
13
mosaic.c
13
mosaic.c
@ -832,21 +832,18 @@ static const char *validate_desc(const game_params *params,
|
|||||||
const char *desc)
|
const char *desc)
|
||||||
{
|
{
|
||||||
int size_dest = params->height * params->width;
|
int size_dest = params->height * params->width;
|
||||||
char *curr_desc = dupstr(desc);
|
|
||||||
char *desc_base = curr_desc;
|
|
||||||
int length;
|
int length;
|
||||||
length = 0;
|
length = 0;
|
||||||
|
|
||||||
while (*curr_desc != '\0') {
|
while (*desc != '\0') {
|
||||||
if (*curr_desc >= 'a' && *curr_desc <= 'z') {
|
if (*desc >= 'a' && *desc <= 'z') {
|
||||||
length += *curr_desc - 'a';
|
length += *desc - 'a';
|
||||||
} else if (*curr_desc < '0' || *curr_desc > '9')
|
} else if (*desc < '0' || *desc > '9')
|
||||||
return "Invalid character in game description";
|
return "Invalid character in game description";
|
||||||
length++;
|
length++;
|
||||||
curr_desc++;
|
desc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sfree(desc_base);
|
|
||||||
if (length != size_dest) {
|
if (length != size_dest) {
|
||||||
return "Desc size mismatch";
|
return "Desc size mismatch";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user