mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32: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:
11
import.c
11
import.c
@ -750,7 +750,7 @@ static struct ssh2_userkey *openssh_pem_read(
|
||||
}
|
||||
|
||||
} else {
|
||||
assert(0 && "Bad key type from load_openssh_pem_key");
|
||||
unreachable("Bad key type from load_openssh_pem_key");
|
||||
errmsg = "Bad key type from load_openssh_pem_key";
|
||||
goto error;
|
||||
}
|
||||
@ -973,8 +973,7 @@ static bool openssh_pem_write(
|
||||
header = "-----BEGIN EC PRIVATE KEY-----\n";
|
||||
footer = "-----END EC PRIVATE KEY-----\n";
|
||||
} else {
|
||||
assert(0); /* zoinks! */
|
||||
exit(1); /* XXX: GCC doesn't understand assert() on some systems. */
|
||||
unreachable("bad key alg in openssh_pem_write");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1363,7 +1362,7 @@ static struct ssh2_userkey *openssh_new_read(
|
||||
keysize = 48; /* 32 byte key + 16 byte IV */
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Bad cipher enumeration value");
|
||||
unreachable("Bad cipher enumeration value");
|
||||
}
|
||||
assert(keysize <= sizeof(keybuf));
|
||||
switch (key->kdf) {
|
||||
@ -1378,7 +1377,7 @@ static struct ssh2_userkey *openssh_new_read(
|
||||
keybuf, keysize);
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Bad kdf enumeration value");
|
||||
unreachable("Bad kdf enumeration value");
|
||||
}
|
||||
switch (key->cipher) {
|
||||
case ON_E_NONE:
|
||||
@ -1408,7 +1407,7 @@ static struct ssh2_userkey *openssh_new_read(
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Bad cipher enumeration value");
|
||||
unreachable("Bad cipher enumeration value");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user