simon-git: puzzles (main): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sat Dec 11 12:04:41 GMT 2021


TL;DR:
  3e00615 Map: add missing sresize in new_game_desc().
  9339cff Palisade: explicitly use 'signed char' for clues.
  5c5c607 malloc.c: fix copy-pasted comment from the Dawn Of Time.
  57fbcd2 malloc.c: check allocation sizes against PTRDIFF_MAX.
  bb1432c gtk.c: squelch uninitialised-variable warning.
  d399a6b tree234: avoid an uninitialised-variable warning.

Repository:     https://git.tartarus.org/simon/puzzles.git
On the web:     https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer:      Simon Tatham <anakin at pobox.com>
Date:           2021-12-11 12:04:41

commit 3e006158451a7ff8f130cbcb7dd80f165a58396e
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=3e006158451a7ff8f130cbcb7dd80f165a58396e;hp=640f9235c79cdb1a924b0148cb312b0f02253364
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Dec 11 11:03:20 2021 +0000

    Map: add missing sresize in new_game_desc().
    
    Every time we append to the string 'ret', we check first that there's
    enough space, and realloc it larger if it's getting close to full.
    Except that I missed one case at the join between the two parts of the
    encoding.
    
    (Spotted because apparently on someone's build platform this led to a
    compiler warning that 'ret' might be null. I think _that's_ not a
    serious worry, but the missing resize was definitely unintentional.)

 map.c | 4 ++++
 1 file changed, 4 insertions(+)

commit 9339cff533fcbf441feef1a5f19163619f8ec1c9
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=9339cff533fcbf441feef1a5f19163619f8ec1c9;hp=3e006158451a7ff8f130cbcb7dd80f165a58396e
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Dec 11 11:09:29 2021 +0000

    Palisade: explicitly use 'signed char' for clues.
    
    Previously, the typedef 'clue' was just 'char', but it was used in the
    expectation that it would be signed. So on platforms that default to
    unsigned char, such as 32-bit Arm, Palisade would completely fail to
    function correctly.

 palisade.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

commit 5c5c607fdb834bc73033736f5774ef53c42008aa
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=5c5c607fdb834bc73033736f5774ef53c42008aa;hp=9339cff533fcbf441feef1a5f19163619f8ec1c9
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Dec 11 11:12:06 2021 +0000

    malloc.c: fix copy-pasted comment from the Dawn Of Time.
    
    My standard 'abort on failure' wrappers around malloc and friends look
    more or less the same in most of my C software. In this case, they
    were so much the same that there was even a comment betraying that I
    copy-pasted them from Halibut. And nobody has noticed in the whole
    lifetime of this code base :-)

 malloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

commit 57fbcd2b29aa74423d47a9efd783a1508ab1bfc5
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=57fbcd2b29aa74423d47a9efd783a1508ab1bfc5;hp=5c5c607fdb834bc73033736f5774ef53c42008aa
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Dec 11 11:13:00 2021 +0000

    malloc.c: check allocation sizes against PTRDIFF_MAX.
    
    I don't expect this to actually come up in any circumstance, but it
    prevents a warning in some versions of gcc that would otherwise arise
    from the use of 'int' to compute the input size: if gcc isn't
    confident that the int is positive, then it complains that possible
    inputs to malloc might be in the region of 2^64 - (small multiple of a
    negative 32-bit int).
    
    I would hope malloc would fail in any case on such an input, so
    failing a couple of lines earlier makes no important difference.
    
    Annoyingly, stdint.h is missing in my NestedVM build setup (though it
    has stdbool.h - it's not _totally_ C90). So I have to check that at
    cmake time.
    
    Also, removed the #defines for smalloc and friends from the tree234
    test mode. These were needed in the old build system, when
    tree234-test was built ad-hoc without being linked against malloc.c.
    But now tree234-test links against the same utils library as
    everything else, and can use the real smalloc - and doing so prevents
    another of these warnings when compiling with -flto.

 cmake/setup.cmake |  6 ++++++
 malloc.c          | 11 +++++++++++
 tree234.c         |  3 ---
 3 files changed, 17 insertions(+), 3 deletions(-)

commit bb1432c0ad0ba2955df9483dde67a987fb946ed8
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=bb1432c0ad0ba2955df9483dde67a987fb946ed8;hp=57fbcd2b29aa74423d47a9efd783a1508ab1bfc5
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Dec 11 11:28:36 2021 +0000

    gtk.c: squelch uninitialised-variable warning.
    
    Apparently some compilers can't work out that new_window() will always
    write to its error-message parameter if it returns failure, so they
    complain at the call site that 'error' might be used uninitialised.
    
    Fix by explicitly initialising it. (To NULL, which really _shouldn't_
    stop the compiler from warning, because surely that's just as bad if
    it reaches the following printf!)
    
    Also, while I'm at it, move it into the block where it's used, so it
    doesn't look as if it might pervade the whole of main().

 gtk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

commit d399a6b23051335ce3107f11822ae352816fcd50
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=d399a6b23051335ce3107f11822ae352816fcd50;hp=bb1432c0ad0ba2955df9483dde67a987fb946ed8
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Dec 11 11:32:25 2021 +0000

    tree234: avoid an uninitialised-variable warning.
    
    Apparently, some compilers can't work out that the pattern
    
      if (!t->root) { special-case handler followed by early return }
      n = t->root;
      while (n) { ... }
    
    will execute the while loop at least once, on the grounds that the
    _first_ test for n being non-NULL must pass, because we initialised n
    from t->root which can't be NULL on any code path where we didn't take
    the early return. So they might give an uninitialised-variable warning
    for the variable 'ki', which is initialised inside the while loop.
    
    Compilers, eh. But it's easy enough to turn the while into a do-while,
    so that even the least alert compiler will know it runs at least once.

 tree234.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)



More information about the tartarus-commits mailing list