The US Torture Bill as C code: debug this, please


My Wired News colleague Kevin Poulsen writes,

I've been puzzling over the Republican bill to deny accused terrorists fair trials, and the seemingly-irrational language champions of the legislation have been using to describe its purpose.

The goal, "is to render justice to the terrorists, even though they will not render justice to us." — Senator Lindsey Graham.

"We don't want (terror suspects) to have everyday rights of American civilians right here. These are war criminals." — Senate Majority Leader Bill Frist.

It occurs to me now that the whole 94-page bill really amounts to a common, one-character programming error.

if (person = terrorist) {
            punish_severely();
} else {
            exit(-1);
}

Can you spot the error? (Solution).

Link to the full text of his Wired News blog entry.

BoingBoing reader comments after the jump.

Reader comment: Chad says,

Yes, I can spot the error, though it may not be the intended one. It's supposed to be "if (person == terrorist)", that's two '=', not one; the comparison operator, not the assignment operator. An assignment operator within a conditional will cause a compiler error.

Xopl says,

The entire point is that programming error… the implication being that
all persons are being assigned the label of terrorist… or that people
can be labeled terrorists by accident… etc.

Chad is forgetting that this is specifically the C programming
language, where that WILL NOT cause a compiler error.

Again, this is the entire point of that code snippet.

You see, in C…

a == b

will return true if a and b have the same value, else false

and…

a = b

will assign a the value of b and return that new value, and anything
non-zero is interpretted as true in C

so that code snippet will always assign person the value of terrorist, and
always punish severely. that's the joke. and it is a common mistake made
with C.

Johnathan Nightingale says,

Dear me, Chad's reply identifies the correct error but rather (I think) misses the humour, since he is "not sure it's the intended one." Spoiler warning for those puzzling it out themselves.

The = vs. == is indeed the intended (and downright witty) error. When this happens in a C program, as it often does, you basically turn the *question* "is this person a terrorist" into the *assertion* "this person is a terrorist." Assignment instead of comparison. As Poulsen quite rightly points out, this error (which, incidentally, has been the root of many a "security" vulnerability) is what the rhetoric these days is espousing — terror suspects (is X a terrorist?) become terrorists (X is a terrorist).

If one were to overextend the metaphor, one might also point out that contrary to Chad's point, this mistake is often NOT caught by the compiler unless appropriate warnings (shall we call them checks and balances?) are in place and functioning correctly. There, now I've gone and spoiled the subtlety. But 500 points to Poulsen for the clever redux.

Loup-Vert says,

About the "Assignment v. Comparison" test: The joke takes on a different meaning in C++. The assignment operator typically returns the value assigned (that is, the statement 'a=25' will return 25). Also, the 'if' conditional test does either a boolean test or a 'not-0' test: Anything in the parentheses that isn't 0 will cause the 'true' branch to execute. In short: Any person tested is a terrorist. Which I think is the originally intended message.

Todd Ogrin says,

The part that worries me most about the code snippet is that "punish_severely()" takes no parameters. Assignment error aside, I would expect it to say "punish_severely(terrorist);"

However, as it stands, all we know is that someone, somewhere is being punished severely, with no apparent relation to their status as a terrorist.

I feel safer already.

Dave Munger says,

Chad is correct in his pointing out the one-character error in the C
code; however he is mistaken in believing that it will produce a
compiler error. It is in fact perfectly legal C code, which makes it
an even more insidious error. Because (person = terrorist) is an
assignment, not a comparison, it will always evaluate to true
(assuming that the value of terrorist is non-zero). Of course, that's
the whole point: they're assuming guilt rather than testing for it.

Giles says,

Thank you for a wonderfully techie post. Perhaps Chad is more used to
a language like Java, where using "=" instead of "==" actually would
generate a compiler error, unless "person" and "terrorist" were
boolean (which would be almost as silly an idea as the legislation
being parodied). Of course, using an OO language for that kind of
code opens a whole different can of worms; is terrorism an IS-A or a
HAS-A relationship? Or, in other words, can people stop being
terrorists? Gosh, that's almost a serious thought…

Chad Arsenault (a different Chad this time) says,

In response to Todd's observation:

Even more worrying, "punish_severely()" is not even defined. So we now know
that someone, somewhere is being punished severely, but we haven't the
slightest idea where or how.

Josh Harle says,

In regards to "The US torture bill as C code", as a computer scientist and political philosopher I can give another perspective.
An exact analogue of the "assigning instead of checking equality" coding problem in deductive reasoning is called "Begging the question". ( link ) This is where the question itself implies a specific answer.

The fresh coding perspective is great for a show of how ludicrous the argument is, though it's a shame the world isn't generally better at critical thinking so that the error would be immediately obvious!