зеркало из https://github.com/github/putty.git
Fix technical-UB uses of the preprocessor.
A recent test-compile at high warning level points out that if you
define a macro with a ... at the end of the parameter list, then every
call should at least include the comma before the variadic part. That
is, if you #define MACRO(x,y,...) then you shouldn't call MACRO(1,2)
with no comma after the 2. But that's what I had done in one of my
definitions of FUNC0 in the fiddly testcrypt system.
In a similar vein, it's a mistake to use the preprocessor 'defined'
operator when it's expanded from another macro. Adjusted the setup of
BB_OK in mpint_i.h to avoid doing that.
(Neither of these has yet caused a problem in any real compile, but
best to fix them before they do.)
(cherry picked from commit f40d31b5cc
)
This commit is contained in:
Родитель
8c227b0cc0
Коммит
5b09e4c250
|
@ -59,7 +59,11 @@
|
||||||
|
|
||||||
/* You can lower the BignumInt size by defining BIGNUM_OVERRIDE on the
|
/* You can lower the BignumInt size by defining BIGNUM_OVERRIDE on the
|
||||||
* command line to be your chosen max value of BIGNUM_INT_BITS_BITS */
|
* command line to be your chosen max value of BIGNUM_INT_BITS_BITS */
|
||||||
#define BB_OK(b) (!defined BIGNUM_OVERRIDE || BIGNUM_OVERRIDE >= b)
|
#if defined BIGNUM_OVERRIDE
|
||||||
|
#define BB_OK(b) ((b) <= BIGNUM_OVERRIDE)
|
||||||
|
#else
|
||||||
|
#define BB_OK(b) (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined __SIZEOF_INT128__ && BB_OK(6)
|
#if defined __SIZEOF_INT128__ && BB_OK(6)
|
||||||
|
|
||||||
|
|
34
testcrypt.c
34
testcrypt.c
|
@ -1001,30 +1001,28 @@ static void process_line(BinarySource *in, strbuf *out)
|
||||||
{
|
{
|
||||||
ptrlen id = get_word(in);
|
ptrlen id = get_word(in);
|
||||||
|
|
||||||
#define DISPATCH_COMMAND(cmd) \
|
#define DISPATCH_INTERNAL(cmdname, handler) do { \
|
||||||
if (ptrlen_eq_string(id, #cmd)) { \
|
if (ptrlen_eq_string(id, cmdname)) { \
|
||||||
handle_##cmd(in, out); \
|
handler(in, out); \
|
||||||
return; \
|
return; \
|
||||||
}
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define DISPATCH_COMMAND(cmd) DISPATCH_INTERNAL(#cmd, handle_##cmd)
|
||||||
DISPATCH_COMMAND(hello);
|
DISPATCH_COMMAND(hello);
|
||||||
DISPATCH_COMMAND(free);
|
DISPATCH_COMMAND(free);
|
||||||
DISPATCH_COMMAND(newstring);
|
DISPATCH_COMMAND(newstring);
|
||||||
DISPATCH_COMMAND(getstring);
|
DISPATCH_COMMAND(getstring);
|
||||||
DISPATCH_COMMAND(mp_literal);
|
DISPATCH_COMMAND(mp_literal);
|
||||||
DISPATCH_COMMAND(mp_dump);
|
DISPATCH_COMMAND(mp_dump);
|
||||||
|
#undef DISPATCH_COMMAND
|
||||||
|
|
||||||
#define FUNC(rettype, function, ...) \
|
#define FUNC0(ret,func) DISPATCH_INTERNAL(#func, handle_##func);
|
||||||
if (ptrlen_eq_string(id, #function)) { \
|
#define FUNC1(ret,func,x) DISPATCH_INTERNAL(#func, handle_##func);
|
||||||
handle_##function(in, out); \
|
#define FUNC2(ret,func,x,y) DISPATCH_INTERNAL(#func, handle_##func);
|
||||||
return; \
|
#define FUNC3(ret,func,x,y,z) DISPATCH_INTERNAL(#func, handle_##func);
|
||||||
}
|
#define FUNC4(ret,func,x,y,z,v) DISPATCH_INTERNAL(#func, handle_##func);
|
||||||
|
#define FUNC5(ret,func,x,y,z,v,w) DISPATCH_INTERNAL(#func, handle_##func);
|
||||||
#define FUNC0 FUNC
|
|
||||||
#define FUNC1 FUNC
|
|
||||||
#define FUNC2 FUNC
|
|
||||||
#define FUNC3 FUNC
|
|
||||||
#define FUNC4 FUNC
|
|
||||||
#define FUNC5 FUNC
|
|
||||||
|
|
||||||
#include "testcrypt.h"
|
#include "testcrypt.h"
|
||||||
|
|
||||||
|
@ -1035,6 +1033,8 @@ static void process_line(BinarySource *in, strbuf *out)
|
||||||
#undef FUNC1
|
#undef FUNC1
|
||||||
#undef FUNC0
|
#undef FUNC0
|
||||||
|
|
||||||
|
#undef DISPATCH_INTERNAL
|
||||||
|
|
||||||
fatal_error("command '%.*s': unrecognised", PTRLEN_PRINTF(id));
|
fatal_error("command '%.*s': unrecognised", PTRLEN_PRINTF(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче