Find the Bug, C# edition
Thanks to Joe Roberts for showing me the code which I’ve rendered below as an exercise in bug-spotting.
The following C# defines a class with a private nullable int field _data
, initialised to null
, and a public int property Data
, which assumes the value of _data
if _data
has a value, or sets _data
to 3
and returns 3
otherwise.
|
|
It is very likely that this code contains a bug. What is the probable bug?
Hint, which you will certainly need
C# compiles down to Microsoft Intermediate Language (“IL”) bytecode. The example above compiles to essentially the following:
|
|
Hint 2
In ROT13:
Gurer’f n enpr pbaqvgvba - jung unccraf va n zhygv-guernqrq pbagrkg?
Answer
In ROT13:
Rkrphgvba ortvaf, naq gur ybpny inevnoyr vf nffvtarq gur qrsnhyg inyhr mreb. Gur guernq vf fhfcraqrq. N arj guernq nfxf sbe gur inyhr bs Qngn, naq pbeerpgyl trgf gur inyhr guerr. Rkrphgvba bs gur bevtvany guernq erfhzrf; qngn abj unf n inyhr, fb jr whzc gb gur svefg ynory, naq erghea gur qrsnhyg inyhr bs na vag, anzryl mreb.