1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Replace assert(false) with an unreachable() macro.

Taking a leaf out of the LLVM code base: this macro still includes an
assert(false) so that the message will show up in a typical build, but
it follows it up with a call to a function explicitly marked as no-
return.

So this ought to do a better job of convincing compilers that once a
code path hits this function it _really doesn't_ have to still faff
about with making up a bogus return value or filling in a variable
that 'might be used uninitialised' in the following code that won't be
reached anyway.

I've gone through the existing code looking for the assert(false) /
assert(0) idiom and replaced all the ones I found with the new macro,
which also meant I could remove a few pointless return statements and
variable initialisations that I'd already had to put in to placate
compiler front ends.
This commit is contained in:
Simon Tatham
2019-01-03 08:12:19 +00:00
parent 61dec9a07a
commit 0112936ef7
27 changed files with 89 additions and 75 deletions

View File

@ -104,7 +104,7 @@ void sk_cleanup(void)
}
void queue_idempotent_callback(IdempotentCallback *ic)
{
assert(0);
unreachable("queue_idempotent_callback called in cmdgen");
}
void showversion(void)
@ -594,7 +594,7 @@ int main(int argc, char **argv)
case SSH_KEYTYPE_OPENSSH_AUTO:
default:
assert(0 && "Should never see these types on an input file");
unreachable("Should never see these types on an input file");
}
}
@ -851,7 +851,7 @@ int main(int argc, char **argv)
break;
default:
assert(0);
unreachable("bad input key type");
}
if (error) {
@ -1044,7 +1044,7 @@ int main(int argc, char **argv)
real_outtype = SSH_KEYTYPE_SSHCOM;
break;
default:
assert(0 && "control flow goof");
unreachable("control flow goof");
}
ret = export_ssh2(outfilename, real_outtype, ssh2key, new_passphrase);
if (!ret) {