1

Hello I am going through the code for pset6 and I cannot figure out what this fields variable is for? They create and init it even test if it is 0 but it is never changed. I am posting a small part of the request function but it is the only part of all the code that it is used in. I just do not understand what it is for. Did they forget to use it or am I missing something. Thanks

        // count fields in message
        int fields = 0;     
        haystack = needle + 2; //move to next byte after '\r\n'
        while (*haystack != '\0')
        {
            // look for CRLF
            needle = strstr(haystack, "\r\n"); //search for this in what is left of haystack [if found there is another field]
            if (needle == NULL)
            {
                break;
            }

            // ensure field is no longer than LimitRequestFieldSize
            if (needle - haystack + 2 > LimitRequestFieldSize)  //(the total size including '\r\n') > MAX FIELD SIZE
            {
                break;
            }

            // look beyond CRLF
            haystack = needle + 2;
        }

        // if we didn't get to end of message, we must have erred
        if (*haystack != '\0')
        {
            break;
        }
        // ensure message has no more than LimitRequestFields
       if (fields > LimitRequestFields) // never going to be true because fields is never used
        {
            break;
        }

1 Answer 1

1

This is a bug in the code that I also noticed. The "request" routine code is missing a "fields++" statement that would increment the counter each time through the while-loop. I found your answer and thought best to post it here. I'm also going to attempt to contact CS50 directly about it.

2
  • Thank you I would love hear what they say about it.
    – arortell
    Commented Apr 4, 2016 at 1:34
  • I emailed Doug Lloyd, one of the instructors. He told me: "I think you might be right about fields; I'll pass that along to be revised for the next time we use that distro! Thanks for bringing it to our attention."
    – Rich Szabo
    Commented Apr 5, 2016 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .