Skip to main content
added 11 characters in body
Source Link

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length]buffer = '\0';realloc(buffer, *length);
    *content = &buffer[0];

    return true;
}

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer = realloc(buffer, *length);
    *content = &buffer[0];

    return true;
}
added 1 character in body
Source Link

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in *content, which apparently takes only charcontent, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in *content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}
added 362 characters in body
Source Link

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work. And because requesting a

As far as I know, by using char* buffer, some 0x00 from jpg via curl is a messfile make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", gdb can't helpso that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to inspectstore the address in *content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work. And because requesting a jpg via curl is a mess, gdb can't help to inspect.

I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}

So far my program passes all but 2 of check50 server2:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

I think they result from the same problem: loading jpg file.

I have gone through some question replies on this website and found out fgetc() can not successfully deal with binary file, such as jpg. So I changed to fread, still does not work.

As far as I know, by using char* buffer, some 0x00 from jpg file make false ends to the string. So I try to imitate how we "fread" jpg in pset 4. I think in pset 4 the program "typedef uint8_t BYTE", so that the 0x00 wouldn't be any problem.

However this time, the program has already set "typedef char BYTE;", so I can not just put " uint8_t* buffer" to store the address in *content, which apparently takes only char.

Please, I'd be grateful for advice!

Here is my load function:

/**
 * Loads a file into memory dynamically allocated on heap.
 * Stores address thereof in *content and length thereof in *length.
 */
bool load(FILE* file, BYTE** content, size_t* length)
{
    if (file == NULL)
    {
        return false;
    }
    
    char* buffer = malloc(1);
    *length = 0;
   
    while (fread(&buffer[*length], 1, 1, file) == 1)
    {
        *length = *length + 1;
        buffer = realloc(buffer, *length + 1);
    }
 
    buffer[*length] = '\0';
    *content = &buffer[0];

    return true;
}
added 33 characters in body
Source Link
Loading
deleted 67 characters in body
Source Link
Loading
Source Link
Loading