CCExtractor Development

Getting started: find the bug in a small code snippet

We recently discovered a small flaw in one of our code sections, and we'd like to invite you to take a look at the function in question, and try to find the mistake.

The function which contains the bug is parsedelay.

This function parses a given parameter (par), and should check if a positive or negative delay should be set in the options.

We expect that you check the code, and send us a reply with how we can fix the issue.

The code for this function is as follows:

int parsedelay (struct ccx_s_options *opt, char *par)
{
    int sign = 0;
    char *c = par;
    while (*c)
    {
        if (*c == '-' || *c == '+')
        {
            if (c != par) // Sign only at the beginning
                return 1;
            if (*c == '-')
                sign = 1;                
            if (*c == '+')
                sign = 1;                
        }
        else
        {
            if (!isdigit (*c))
                return 1;
            opt->subs_delay = opt->subs_delay*10 + (*c-'0');
        }
        c++;
    }
    if (sign)
        opt->subs_delay = -opt->subs_delay;
    return 0;
}

Note: in order to find this bug you don't need to run or compile anything. Just thinking logically while going over the code should be sufficient to find the one bug we're after.

Task tags

  • c
  • bug
  • bug fixing

Students who completed this task

Himanshu Sekhar Nayak, Kartik, Matt, Jake Wagner, Tanner Weinacker, Hori75, Callum F^, Harry Yu, Ethan Yang, Jorrell Templeton, PiyushGupta, Benjamin Mueggenburg, Andreea Zaharia, Hemang Rajvanshy, Aleksey Abakhtimov, Govind Balaji S, Athena, gbui, dKimchi, Ryo Armanda

Task type

  • code Code

Level

Beginner
close

2017