1
$\begingroup$

The software for launching the missiles was designed so that both captain and co-captain had to press their LAUNCH button at the same time in order to trigger a launch. During testing it was discovered that if either operator pressed their LAUNCH button, the missiles would launch.

"I don't get it," said Barbara the software engineer as she looked at the code. "It clearly says AND:"

if (button1Voltage == HIGH && button2Voltage == HIGH) {
    missileRelay.setVoltage(HIGH);
}
else {
    missileRelay.setVoltage(LOW);
}

What was causing the bug?

$\endgroup$
  • $\begingroup$ Maybe && is not AND but OR. $\endgroup$ – user18031 Jun 28 '16 at 7:41
  • 2
    $\begingroup$ If && = OR, then the code is worthless, since any of it could mean anything. $\endgroup$ – JakeSteam Jun 28 '16 at 8:24
  • 10
    $\begingroup$ After recent cutbacks, the military has been forced to use StackExchange for all debugging and Q/A of missile launch systems... $\endgroup$ – Travis Don Kindred Jun 28 '16 at 14:31

11 Answers 11

25
$\begingroup$

A potential answer:

The system uses low-true logic, the button value is high only if it isn't pressed, and the missiles are only launched if voltage is low.

$\endgroup$
  • $\begingroup$ If either of them press the button, both button voltage would be different. Isn't it? $\endgroup$ – Mohit Jain Jun 28 '16 at 5:44
  • 1
    $\begingroup$ @MohitJain if either of them press the button, both voltages wouldn't be HIGH anymore, meaning it'd go to the else and launch the missile. $\endgroup$ – Quark Jun 28 '16 at 5:45
  • $\begingroup$ This is what I thought too $\endgroup$ – Mario Garcia Jun 28 '16 at 8:43
  • 4
    $\begingroup$ If so, it's a pretty dangerous missile system; if the power fails to the relay but not to the launching mechanism the missiles also launch :( (unless LOW is still a true voltage I guess) $\endgroup$ – Jonathan Allan Jun 28 '16 at 8:50
  • $\begingroup$ If you invert all inputs and outputs of an and-gate, it is the same as an or-gate, which is basically what happens here. $\endgroup$ – Kruga Jun 28 '16 at 9:02
3
$\begingroup$

Surely in a true missile system...

you wouldn't set the voltage "low" as it could still invoke enough voltage to initiate launch. A more reliable solution would be to "ground" both firing lines using a dual line relay.

Also,

the inference of a "Captain" implies this is installed on a ship/platform? then it could be the movement of the metal hulled ship passing through the earths magnetic fields, inducing current into the superstructure without suitable degaussing in place.

Just sayin'

$\endgroup$
3
$\begingroup$

Another possible bug:

button1Voltage and button2Voltage are references to the same variable.

Which could look something like this in C++:

bool button1Voltage; bool &button2Voltage = button1Voltage; // so now setting either will set them both.

$\endgroup$
  • $\begingroup$ That would not launch if either of them pressed button. $\endgroup$ – Edheldil Jun 28 '16 at 16:53
  • $\begingroup$ @Edheldil just added some clarification. I know this is a huge assumption. $\endgroup$ – flu Jun 28 '16 at 17:03
  • $\begingroup$ That isn't valid C; that's a C++ism. (You can achieve the same effect in C by using the preprocessor.) $\endgroup$ – Peregrine Rook Jun 28 '16 at 19:37
1
$\begingroup$

It is possible that

The values of button2Voltage and button1Voltage are not being reset so they remain HIGH once pressed.

$\endgroup$
1
$\begingroup$

The && operator is potentially

overloaded to the || operator, making it an OR instead of an AND

$\endgroup$
  • 3
    $\begingroup$ Dear god I would certainly hope not $\endgroup$ – Business Cat Jun 28 '16 at 16:25
1
$\begingroup$

Perhaps the bug is

in the hardware rather than the software. The buttons have been wired up in parallel rather than in series, and the voltage measurements for both buttons are effectively measuring the same voltage.

$\endgroup$
1
$\begingroup$

Since this isn't the entire source code of the program, it's easy to contrive a scenario in which a bug has been introduced on a new line.

Take this one, for example:

button1Voltage = (button1Voltage == HIGH || button2Voltage == HIGH) ? HIGH : LOW;
button2Voltage = button1Voltage;
if (button1Voltage == HIGH && button2Voltage == HIGH) {
  missileRelay.setVoltage(HIGH);
}
else {
  missileRelay.setVoltage(LOW);
}
$\endgroup$
1
$\begingroup$

Maybe somewhere in the process the values are coerced into boolean?

const bool HIGH=true;
const bool LOW=false;

int main() {
    bool a;
    bool b;

    a=-1;
    b=1;

    if (a==HIGH && b==HIGH) {
        puts("boom!");
    } else {
        puts("...");
    }
}

... or buttonVoltage has a type with == overloaded to do that coercion on its arguments

$\endgroup$
0
$\begingroup$

I was thinking the same as nikamed earlier, but there's not too much other code which would help us know that.

Newest idea is:

Maybe the missiles get launched when the voltage is set to LOW?

$\endgroup$
0
$\begingroup$

Another possibility is that

HIGH=2 and LOW=1 ... and LOW is good enough to launch :)

Or even better:

LOW=-1, HIGH=1 and any nonzero voltage will cause the launch

$\endgroup$
-1
$\begingroup$

HIGH = 0; LOW = 1;

Same result as Quark's answer.


Edit:

To clarify, if the HIGH and LOW constants were accidentally set the wrong way around in the code, then the desired bug would appear. When neither button is pressed (both HIGH), then button1Voltage == HIGH && button2Voltage == HIGH, so the missile is set to HIGH i.e. not launched. If either or both buttons are pressed, the missile is launched.

.

This is not quite the same as Quark's answer, but has the same result.

$\endgroup$
  • $\begingroup$ Can you explain why? $\endgroup$ – Beastly Gerbil Jun 28 '16 at 18:20
  • $\begingroup$ ok, I've updated the answer $\endgroup$ – Zantier Jun 29 '16 at 9:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.