Help!! I'm currently struggling with Parse with check50 reporting three errors as follows:

enter image description here

Here is the sandbox report

And here is my parse code..

bool parse(const char* line, char* abs_path, char* query)


    char req_line[strlen(line) + 1];
    strcpy(req_line, line);
    int i = 0;

    char* method = strtok(req_line, " ");
    char* req_tar = strtok(NULL, " ");
    char* version = strtok(NULL, "\r\n\r\n");
    abs_path = strtok(req_tar, "?");

    if(strcmp(req_tar, abs_path) != 0)
        query = strstr(req_tar, abs_path);

    if(query[i] == '?' && strlen(query) == 1)
        query[0] = '\0';

    if(strcmp(method, "GET") != 0)
        return false;

    if(req_tar[0] != '/')
        return false;

    if(req_tar[i] == '"')
        return false;

    if(strcmp(version, "HTTP/1.1") != 0)
        return false;

        return true;

Could someone please give me a hint where the problem lies?

Thanks in advance.


This error Requesting request-target with " returns error code 400 is from here:

if(req_tar[i] == '"') { error(400); return false; }

because i is always 0.

The other two errors indicate a problem with abs_path. Scope. Pointers. You are giving abs_path a new address here abs_path = strtok(req_tar, "?");. It is pointing to an address within req_tar, which is a local variable. As such, that memory is destroyed when control returns to main. Main is looking at abs_path at the address it was "assigned" when it was declared in main here char abs_path[LimitRequestLine + 1];. The contents of that memory have not been changed. You need to create abs_path a different way, perhaps with a string function like strncpy. There are many possible approaches.

  • Thanks heaps for the tips!! I have now passed server1 check50 and moving on to do load and indexes...
    – MTreacy
    Nov 17 '16 at 23:54

You must log in to answer this question.

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