simon-git: putty (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Mon Oct 14 20:08:36 BST 2019
TL;DR:
1547c9c1 Make dupcat() into a variadic macro.
Repository: https://git.tartarus.org/simon/putty.git
On the web: https://git.tartarus.org/?p=simon/putty.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2019-10-14 20:08:36
commit 1547c9c1ec44077e4b9d1506e880820cbed8e319
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=1547c9c1ec44077e4b9d1506e880820cbed8e319;hp=283bd541a61555cd3ab18e3c686894dcc6576b1b
Author: Simon Tatham <anakin at pobox.com>
Date: Mon Oct 14 19:42:37 2019 +0100
Make dupcat() into a variadic macro.
Up until now, it's been a variadic _function_, whose argument list
consists of 'const char *' ASCIZ strings to concatenate, terminated by
one containing a null pointer. Now, that function is dupcat_fn(), and
it's wrapped by a C99 variadic _macro_ called dupcat(), which
automatically suffixes the null-pointer terminating argument.
This has three benefits. Firstly, it's just less effort at every call
site. Secondly, it protects against the risk of accidentally leaving
off the NULL, causing arbitrary words of stack memory to be
dereferenced as char pointers. And thirdly, it protects against the
more subtle risk of writing a bare 'NULL' as the terminating argument,
instead of casting it explicitly to a pointer. That last one is
necessary because C permits the macro NULL to expand to an integer
constant such as 0, so NULL by itself may not have pointer type, and
worse, it may not be marshalled in a variadic argument list in the
same way as a pointer. (For example, on a 64-bit machine it might only
occupy 32 bits. And yet, on another 64-bit platform, it might work
just fine, so that you don't notice the mistake!)
I was inspired to do this by happening to notice one of those bare
NULL terminators, and thinking I'd better check if there were any
more. Turned out there were quite a few. Now there are none.
cmdgen.c | 2 +-
config.c | 6 +++---
misc.h | 3 ++-
pscp.c | 15 +++++++--------
psftp.c | 14 +++++++-------
settings.c | 3 +--
ssh2transport.c | 4 +---
sshgssc.c | 2 +-
sshshare.c | 2 +-
unix/gtkdlg.c | 10 +++++-----
unix/gtkfont.c | 13 +++++--------
unix/gtkwin.c | 11 +++++------
unix/ux_x11.c | 4 ++--
unix/uxpgnt.c | 2 +-
unix/uxpty.c | 2 +-
unix/uxputty.c | 4 ++--
unix/uxsftp.c | 2 +-
unix/uxshare.c | 6 +++---
unix/uxstore.c | 6 +++---
utils.c | 2 +-
windows/windlg.c | 2 +-
windows/wingss.c | 2 +-
windows/winjump.c | 5 ++---
windows/winmisc.c | 2 +-
windows/winpgnt.c | 2 +-
windows/winsftp.c | 8 ++++----
windows/winstore.c | 24 ++++++++++--------------
27 files changed, 73 insertions(+), 85 deletions(-)
More information about the tartarus-commits
mailing list