CS 3733 Operating Systems, Fall 2001 Assignment 1 Comments
The assignment was graded on a basis of 30 points.
A circled number on your assignment corresponds to one of these:
- If an error occurs, free unneeded memory,
for example, if the host name file not fit
- Do not free the node before you free the key. Understand why.
- Use lint -Xarch=v9
- Cannot free entryp -> node.data.host
- You must use proper indentation
- Do not use malloc for small block of known size
- You must understand all lint warnings
- Do not hard code numeric values, use symbolic values
- It is an error if strlen(host)==HOSTSIZE since this does not
leave space for the string terminator.
- If you use strncpy on the key, you must make sure a string terminator is
put in.
- You must allocate space for the key in addentry, not just set a pointer.
- You can only free memory that was allocated with malloc (or one of its variations).
One point was taken off for each of these except for number 11 which made the
assignment much easier. This error cost you 3 points.
Testing:
You were to make up your own tests, not just use the tests that I provided.
Your commentary should say more than "I tested the program."
This time I did not take off much for poor testing.
Next time will be different.
A T1 on your paper indicates that
insufficient testing was done and you lost 1 point.
A T2 indicates
that some testing was done, but not enough.
You need to test all of the functions with data that checks all possible
return values, including host name too large. Testing for handling of
malloc failures is difficult. Think up a way to do this.
Question answers
I did not check your answers on this assignment unless I needed to see what
you understood. This was done mainly for those who did not get the
program working.
- What would happen if after a successful addentry call, the
calling program modified the string it passed as a key?
Nothing, since addentry makes a copy of the key.
- What would happen if after a successful addentry, the
calling program modified the string it passed as a host name?
Nothing, since addentry makes a copy of the host name.
- Suppose addentry used the pointer to the key rather
than creating new space and copying the key. How could the calling
program corrupt the database?
The calling program later change the contents of the key and thus
modify the database without calling the database routines.
- How did you test that your program does not have any memory leaks?
Do a number of large adds and deletes and see what happens to the
memory usage of the program. The heap should not keep growing.
I did this using the PIOCSTATUS ioctl system call. (See PUP, page 131.)
One person said he put up a memory usage monitor.
Most people did not know how to check for this. (This is OK, for now.)
- getdata and findentry are passed buffers in which to
store the strings to be returned. These strings are copied into
buffers supplied to the calling program. An alternative would be
to return pointers to these strings inside the database.
Give at least two reasons for not doing it this other way.
1) After a pointer is returned, a call to delteentry could free the
memory, making access to it illegal.
2) The calling program could corrupt the database.
- findentry handles length errors for host and
key differently. If the host does not fit, it is considered
a fatal error (-1 is returned) while if the key dies not fit, part
of the key is copied and no error is generated. Why is it done this
way?
A truncated key could still be used to decide whether or not the
data is useful. A truncated host name would not allow you to contact
the host containing the data.
- The file datalib.h contains prototypes of the functions
in datalib.c but the typedefs used in
datalib.c are not in this file. Why is that?
The typedefs are part of the implementation of the database and should
be hidden from the user of the database.