mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00:00
Fix a few warnings reported by Visual Studio.
Many of VS's warnings are too noisy to be useful, but I just tried the experiment of turning off the unrecoverable ones and seeing what was left, and I found a couple of things that actually seem worth fixing. In a few cases in mpint.c, and in one case in sshzlib.c, we had the idiom 'size_t var = 1 << bitpos;', and VS pointed out that when '1' is implicitly a 32-bit int and 'size_t' is 64 bits, this is probably not what you wanted. Writing '(size_t)1 << bitpos' is safer. Secondly, VS complained about lots of functions failing to return a value, or not returning a value on every code path. In every case this was somewhere that we'd used the local unreachable() idiom to indicate that those code paths didn't return at all. So the real problem was that that idiom didn't work in VS. And that's not because VS _can't_ mark functions as noreturn: it has a perfectly good declspec for it. It was just that we hadn't actually _done_ it. Now added a clause in the #if in defs.h that spots VS and uses the declspec.
This commit is contained in:
parent
7c42ca0280
commit
736646b0c9
2
defs.h
2
defs.h
@ -184,6 +184,8 @@ typedef struct PacketProtocolLayer PacketProtocolLayer;
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
#define NORETURN __attribute__((__noreturn__))
|
||||
#elif defined _MSC_VER
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#else
|
||||
#define NORETURN
|
||||
#endif
|
||||
|
8
mpint.c
8
mpint.c
@ -1183,7 +1183,7 @@ static void mp_rshift_safe_in_place(mp_int *r, size_t bits)
|
||||
mp_cond_clear(r, clear);
|
||||
|
||||
for (unsigned bit = 0; r->nw >> bit; bit++) {
|
||||
size_t word_offset = 1 << bit;
|
||||
size_t word_offset = (size_t)1 << bit;
|
||||
BignumInt mask = -(BignumInt)((wordshift >> bit) & 1);
|
||||
for (size_t i = 0; i < r->nw; i++) {
|
||||
BignumInt w = mp_word(r, i + word_offset);
|
||||
@ -1232,7 +1232,7 @@ static void mp_lshift_safe_in_place(mp_int *r, size_t bits)
|
||||
mp_cond_clear(r, clear);
|
||||
|
||||
for (unsigned bit = 0; r->nw >> bit; bit++) {
|
||||
size_t word_offset = 1 << bit;
|
||||
size_t word_offset = (size_t)1 << bit;
|
||||
BignumInt mask = -(BignumInt)((wordshift >> bit) & 1);
|
||||
for (size_t i = r->nw; i-- > 0 ;) {
|
||||
BignumInt w = mp_word(r, i - word_offset);
|
||||
@ -2042,7 +2042,7 @@ void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q_out, mp_int *r_out)
|
||||
*/
|
||||
size_t shift_up = 0;
|
||||
for (size_t i = BIGNUM_INT_BITS_BITS; i-- > 0;) {
|
||||
size_t sl = 1 << i; /* left shift count */
|
||||
size_t sl = (size_t)1 << i; /* left shift count */
|
||||
size_t sr = 64 - sl; /* complementary right-shift count */
|
||||
|
||||
/* Should we shift up? */
|
||||
@ -2079,7 +2079,7 @@ void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q_out, mp_int *r_out)
|
||||
* instructions, e.g. by splitting up into cases.
|
||||
*/
|
||||
for (size_t i = BIGNUM_INT_BITS_BITS; i-- > 0;) {
|
||||
size_t sl = 1 << i; /* left shift count */
|
||||
size_t sl = (size_t)1 << i; /* left shift count */
|
||||
size_t sr = 64 - sl; /* complementary right-shift count */
|
||||
|
||||
/* Should we shift up? */
|
||||
|
@ -730,7 +730,7 @@ static struct zlib_table *zlib_mkonetab(int *codes, unsigned char *lengths,
|
||||
int pfxmask = (1 << pfxbits) - 1;
|
||||
int nbits, i, j, code;
|
||||
|
||||
tab->table = snewn(1 << bits, struct zlib_tableentry);
|
||||
tab->table = snewn((size_t)1 << bits, struct zlib_tableentry);
|
||||
tab->mask = (1 << bits) - 1;
|
||||
|
||||
for (code = 0; code <= tab->mask; code++) {
|
||||
|
Loading…
Reference in New Issue
Block a user