Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Secure Coding Lab Zune Failure Part 1 Purpose: Explore the Zune Failure from Dec

ID: 3808280 • Letter: S

Question

Secure Coding Lab

Zune Failure Part 1

Purpose:              Explore the Zune Failure from December 2008.

Tools:                    Students can use any tool of their choice

Assignment:       Students will do individual work.   The deliverable is an explanation of the code that resulted in the Microsoft Zune failure of December 31, 2008. Code is attached.

Deliverable:        Analyzing the code, explain why it failed, show the specific lines of code with an explanation of why. And how to fix it.

Due Date:            Beginning of class 1 week after assignment

Code:

#define ORIGINYEAR 1980

BOOL ConvertDays(UINT32 days, SYSTEMTIME* lpTime)

{

    int dayofweek, month, year;

    UINT8 *month_tab;

    //Calculate current day of the week

    dayofweek = GetDayOfWeek(days);

    year = ORIGINYEAR;

    while (days > 365)

    {

        if (IsLeapYear(year))

        {

            if (days > 366)

            {

                days -= 366;

                year += 1;

            }

        }

        else

        {

            days -= 365;

            year += 1;

        }

    }

    // Determine whether it is a leap year

    month_tab = (UINT8 *)((IsLeapYear(year))? monthtable_leap : monthtable);

    for (month=0; month<12; month++)

    {

        if (days <= month_tab[month])

            break;

        days -= month_tab[month];

    }

    month += 1;

    lpTime->wDay = days;

    lpTime->wDayOfWeek = dayofweek;

    lpTime->wMonth = month;

    lpTime->wYear = year;

    return TRUE;

}

Explanation / Answer

In case, if year is a leap year but the days value is 366, then

while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}

Code will enter into the while loop as days=366 are > 365 and check   if (IsLeapYear(year)), which is also true, as we are assuming this is a leap year.. Now days are exactly 366, hence code will not enter into if condition of  if (days > 366) and then again go back to check the while loop condition of  while (days > 365), this will result into an infinite loop, hence failure of the code.

Code can be rectified using a while loop as shown below:

while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
} else {
               break;
           }
}
else
{
days -= 365;
year += 1;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote