aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-13 21:00:11 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-13 21:00:11 +0000
commitda2767a3f9bf4abb0436157972366202ad53a407 (patch)
tree59afe74c516488e277b573295ec594bc0a1f6860
parente336513be755159158c5ba017c91b018ad4cd36c (diff)
downloadpuzzles-da2767a3f9bf4abb0436157972366202ad53a407.zip
puzzles-da2767a3f9bf4abb0436157972366202ad53a407.tar.gz
puzzles-da2767a3f9bf4abb0436157972366202ad53a407.tar.bz2
puzzles-da2767a3f9bf4abb0436157972366202ad53a407.tar.xz
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.
-rw-r--r--mosaic.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/mosaic.c b/mosaic.c
index 74a06d0..39d368a 100644
--- a/mosaic.c
+++ b/mosaic.c
@@ -832,21 +832,18 @@ static const char *validate_desc(const game_params *params,
const char *desc)
{
int size_dest = params->height * params->width;
- char *curr_desc = dupstr(desc);
- char *desc_base = curr_desc;
int length;
length = 0;
- while (*curr_desc != '\0') {
- if (*curr_desc >= 'a' && *curr_desc <= 'z') {
- length += *curr_desc - 'a';
- } else if (*curr_desc < '0' || *curr_desc > '9')
+ while (*desc != '\0') {
+ if (*desc >= 'a' && *desc <= 'z') {
+ length += *desc - 'a';
+ } else if (*desc < '0' || *desc > '9')
return "Invalid character in game description";
length++;
- curr_desc++;
+ desc++;
}
- sfree(desc_base);
if (length != size_dest) {
return "Desc size mismatch";
}