Skip to content
Snippets Groups Projects
  • Simon Tatham's avatar
    736646b0
    Fix a few warnings reported by Visual Studio. · 736646b0
    Simon Tatham authored
    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.
    736646b0
    History
    Fix a few warnings reported by Visual Studio.
    Simon Tatham authored
    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.