Hot answers tagged

3 votes
Accepted

Pset6 problem in indexes and load function

Here are specific things to look at: load Declare c as an int instead of size_t, since size_t is unsigned. indexes Your allocation for path2 is wrong char* path2 = (char*)malloc(sizeof(strlen(php) ...
user avatar
2 votes

error in load and indexes function

Reread the specification for indexes in the instructions. Complete the implementation of indexes in such a way that the function, given a /path/to/a/directory, returns /path/to/a/directory/index....
user avatar
2 votes
Accepted

server.c indexes - what is to be done?

If it exists, you simply have to return its path, as a string. For example, if the input is the string /gifs/cats, and there is indeed a file named index.html in the /gifs/cats directory, then you ...
user avatar
  • 188
1 vote

Indexes function playing a sort of infinite loop

Response to edit#1: NB: The code post turned char* html = malloc(12); into this char html = malloc(12); which was only confusing for a little while :) A major problem you are encountering is your ...
user avatar
1 vote
Accepted

indexes function again

The function signature of strstr is char *strstr(const char *haystack, const char *needle) Since you have declared needle a const char*, you are violating the contract. I recommend further ...
user avatar
1 vote

PSET6 Indexes Doesn't Work

First, verify your directory structure is correct. From the instructions, when the distro code is unzipped your "tree" from the pset6 directory should look like this: . ├── Makefile ├── public │...
user avatar
1 vote

Pset6 Server works fine for cat.jpg, but fails check50

Turns out I read the spec wrong and was returning the wrong string in my lookup function...so silly. All is well now!
user avatar
  • 120
1 vote
Accepted

pset6 server.c 403 forbidden for "/", problems for lookup and indexes

Hint: This line in indexes if (access(phpcheck, F_OK)) (and the other access) is wrong. Suggestion: Read man access. Pay special attention to the RETURN section. access returns an int. Treat it like ...
user avatar
1 vote
Accepted

Pset6 Indexes Server.c - Segmentation Fault

There are problems in this index function. However, they are not causing all the check50 failures. Those problems probably stem from load function. Since check50 (probably) makes a direct request to ...
user avatar
1 vote
Accepted

Pset6: Errors with Check50

Your question is too extensive, I am not a person who likes to reprimand anyone, but the work of debugging the program has to leave you, the time required to check and respond to all errors is very ...
user avatar
  • 5,172
1 vote
Accepted

indexes function in server.c

You'll upload server.c to the staff's computer and the file will be tested there in their directories, not in your directories. And they decided that the files will be called index. If this answers ...
user avatar
1 vote
Accepted

Need help with load function pset6

load buffer is allocated for one byte here BYTE* buffer = malloc(sizeof(BYTE)); This while(fread(buffer, 512, 1, file) == 1) reads 512 bytes into buffer. And buffer is only and ever allocated for ...
user avatar
1 vote
Accepted

Pset6: load() and indexes() fail check50 server2 (but parse() and lookup() pass check50 server1)

[answer removed to respect the Honor Code]
user avatar
1 vote
Accepted

pset6 server2 /dir/ malloc [SOLVED]

Your function now has index.php written two times. One here: strcat(php, "index.php"); Another here: strcat(html, "index.php");
user avatar
1 vote
Accepted

How/when to free this memory? (pset6/server)

Does valgrind return the leak if it finds index.html or index.php? I would predict this indexes would leak memory only if neither of those files is "found". Generally speaking, one would not change ...
user avatar
1 vote
Accepted

check50 fails on pset6 possibly indexes function

The old sizeof trap. strlen(path) + strlen(php) + 1 returns an integer. sizeof an integer is 4. In two places. Do not use sizeof. Here is a good explanation. Think about this, if you allocate dir for ...
user avatar
1 vote

Pset6: How to debug load() and indexes()?

Here's what I do. Use debug50 instead of the command line gdb. If you haven't used that before: Run update50 to be sure you are up to date (the IDE is on version 81 at the moment). Then, here's ...
user avatar
  • 18.4k
1 vote
Accepted

Pset 6 failing checks on indexes

sizeof bad. char* temp_path = malloc(sizeof(path)); path is a pointer. sizeof a pointer is 4 or 8 depending on architecture. Looks like you want the length of the strings, which is a different ...
user avatar
1 vote
Accepted

pset6 | Server.c | load and indexes doesn't work

Low hanging fruit (since you give no indication what problems you are experiencing). indexes Read the man page on access and pay special attention to the return value. Spoiler: it ain't a bool. ...
user avatar
1 vote
Accepted

PSET6 Indexes wrong condition followed

If you are going to treat array and array2 as string literals, why not declare them as such (eg char* array = "index.php"). No allocation muss, no null-terminator fuss. gdb hint: inspect the value of ...
user avatar
1 vote

Pset6 problem in indexes and load function

gdb to the rescue! Open two terminals. In the first, call gdb ./server. There's a guide here. Of course, you will set a breakpoint at load instead of parse. In the second terminal, cd to your ...
user avatar
1 vote

PSET6 again: pages not loading, but getting 200 OK

After a lot of help from DinoCoderSaurus, I have finally figured out what was wrong with my code. First of all, I wasn't incrementing length properly in load. Then I wasn't returning anything when ...
user avatar
1 vote
Accepted

Pset6 Unexpected end of input

Unexpected end of input Indicates a timeout on the check50 server. It has not processed your request. The only advice is "try again later". error 404 Assuming you mean the "non_existAnt" file ...
user avatar
1 vote

Pset6 Indexes free() invalid next size error

sizeof (char), the sizeof operator returns the size in bytes of char, most likely to be 1, so that path_php has the same longuitud that path. Sure you know which is the mistake that you make.
user avatar
  • 5,172
1 vote
Accepted

pset6 indexes problem with string pointers

first I wanna mention that it's really bad practice to have magical numbers (e.g., 10 and 11) in your code as they make your code difficult to understand. second, you don't really need to check ...
user avatar
  • 17.4k
1 vote
Accepted

Pointer to char comes back empty

Scope. Pointers. Look at the difference between the way you create abs_path and the way you create query. This strncpy(abs_path, reqtar, aplen); changes the contents of the memory that abs_path points ...
user avatar
1 vote
Accepted

pset6: PHP Templating and Indexes

about your /test problem, you forgot to check if the path already has a '/' at the end, and add it if it's not the case.
user avatar
1 vote
Accepted

Images Not Loading in Server.c, but Getting 200 OK Response

EDIT Sorry again for the misdirect. The elusive 1 eludes me at least once a day. This strncpy(storage, buffer, count); is causing a problem. Content can be anything. And content can have bytes with ...
user avatar
1 vote
Accepted

Pset6: server is functional but still failing a few checks

How many bytes have you allocated to pathcopy? How many bytes are you trying to stuff in it? (Ditto pathcopy2). Once you fix that, make sure newpath is sized properly. Also here's more trouble your ...
user avatar
1 vote
Accepted

Server.c Indexes function outputs weird code

according to the specs, you should first check for index.php's existence and return a path to it, if it exists. then check for index.html's existence, and return a path to it, if it exists. otherwise, ...
user avatar
  • 17.4k

Only top scored, non community-wiki answers of a minimum length are eligible