0

EDIT: Fixed some more stuff, but remain stuck. Will continue troubleshooting, but would still appreciate input :)

New code here: http://pastebin.com/gQyqPx99

Hello! I'm really stuck on pset6 server, and I think the problem is with my load function. I tried three or four different approaches did a lot of googling and have done my best with debug50 and gdb, but I haven't been able to figure out what's wrong. Any hints would be really appreciated as I've been stuck on this for a week! Check50 returns:

~/workspace/pset6/ $ check50 2015.fall.pset6.server2 server.c
:) server.c exists
:) server compiles
:( Requesting cat.jpg returns 200, image/jpeg, and correct image
:( Requesting cat.html returns 200, text/html, and correct file
:( Requesting cat2.HTML returns 200, text/html, and correct file
:( Requesting cat3.HtMl returns 200, text/html, and correct file
:( Requesting cat.gif returns 200, image/gif, and correct file
:( Requesting favicon.ico returns 200, image/x-icon, and correct file
:( Requesting test.css returns 200, text/css, and correct file
:( Requesting test.js returns 200, text/javascript, and correct file
:) Requesting hello.php returns 200, text/html, and correct output
:) Requesting hello.php? returns 200, text/html, and correct output
:) Requesting hello.php?name=Alice returns 200, text/html, and correct output
:) Requesting /test redirects to /test/
:( Requesting /test/ outputs /test/index.html
\ expected an exit code of 0, not standard error of "======= Backtrace:     =========\n======= M..."
:( Requesting directory containing index.php outputs index.php
\ expected output, not standard error of "======= Backtrace: =========\n"
:( Requesting two files in a row (cat.html then cat.jpg) succeeds
https://sandbox.cs50.net/c…/f78c1f9cbb4f41348caa461ef0e52eab

Here is my code: http://pastebin.com/gQyqPx99

1

This \ expected an exit code of 0, not standard error of "======= Backtrace: =========\n...... is a seg fault. At least one problem is in indexes char* path0 = malloc(sizeof(path) + 1);. path is a pointer. sizeof a pointer is 8. You probably meant the length of path. (Ditto path1 and path2). Speaking of path1 and path2, they will be "longer than" path, so they are underallocated.

You might want to try debug50 or gdb (tips here) to help you troubleshoot the load function. Your best bet would be to use a curl request to a small text file, like hello.html (curl -i http://localhost:8080/hello.html). I suspect this *content = &buffer[0]; is a major problem. Do you want *content to be the address of buffer? You want it to point to the same memory that buffer points to.

2
  • Thank you, very helpful! I fixed the issues you noted (updated code above) and took a closer look with gdb - the contents of buffer seem to be ok for hello.html (0x607330, is that right?) but unfortunately I'm still getting caught up by check50, and things aren't loading properly. I'll go through everything carefully again but if you have any further hints I'd be grateful.
    – J M COOPER
    Oct 5 '16 at 14:12
  • Probably declaring buffer a char*. Remember, a char* is "done" when it encounters the null terminator, a zero byte. Image files can have 0 bytes, think black pixel. Take this (from the spec) Note that content is a "pointer to a pointer" (i.e., BYTE*), as a hint. Oct 5 '16 at 15:39

You must log in to answer this question.

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