How a Simple Leap-Year Logic Mistake Turned Zune’s Date Driver into a Legendary Bug
A historic bug in Microsoft Zune’s date‑update driver arose from a flawed leap‑year handling loop, and the article explains the faulty code, why it failed, its wide impact, and how thorough boundary‑value testing could have prevented it.
Recently a post highlighted a famous bug in Microsoft Zune’s built‑in date‑update driver. The problematic source code is shared below.
while (days > 365) {
if (IsLeapYear(year)) {
if (days > 366) {
days -= 366;
year += 1;
}
} else {
days -= 365;
year += 1;
}
}This loop is intended to adjust the year and remaining days when the day count exceeds a year’s length, accounting for leap years. The outer while runs while days is greater than 365. If the current year is a leap year, the inner condition checks whether days exceeds 366 before subtracting 366 and incrementing the year; otherwise it subtracts 365.
The logic flaw lies in the condition ordering: when days equals 366 in a leap year, the inner if (days > 366) fails, so the code never processes that exact boundary. Consequently the loop can become infinite or produce incorrect dates, creating the notorious bug.
Although the algorithm is simple, its impact was large because the code is easy to understand and the testing difficulty is low. The incident serves as a reminder that even the most basic functionality must be thoroughly tested.
For effective testing, the article suggests designing test cases around two variables: the year (with IsLeapYear() returning true or false) and the day count. Boundary values for days should include 365, 366, and 367. Combining these with both leap‑year and non‑leap‑year scenarios yields a comprehensive set of test cases that would expose the flaw.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
