Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming tests on pencil & paper?

Name: Anonymous 2007-05-31 21:35 ID:YTnK448u

How hard is it to cut off access to the Internet in a computer lab and give programming tests with a text editor and compiler? Do most universities administer tests on programming on paper, or does my school (a state university) just suck? I would have been done with that test today way faster if I had access to cutting and copying and shit, not to mention who writes a program and doesn't even compile it?

Name: Anonymous 2007-06-01 14:15 ID:1SOuASvj

>>1
All universities suck. You cannot learn programming from a university.
No programmer EVER writes code in paper.
He either uses vim or emacs. (Or MSVC, ew.)
How hard it is to cut off the internet in some computers?
Not hard at all.
If they wanted you to write code without compiling it they could just remove the access to the compiler.

>>7
Wrong. FFS, how do you think most bugs are being found to applications? nope, not when compiling but when people use them for stupid/weird things.
Take this for example

int main() {
char buffer[100];
fgets(buffer, 100, stdin);
printf(buffer);
return 0;
}

This is a basic 'echo' program with 2 problems.
1) the user might not enter a 0 eg
cat file | ./program
If `file' does not contain a null byte printf() will access unitiliazed elements of buffer. Those elements will contain what was before buffer in the stack, let's suppose there weren't any 0 bytes there too, then printf() will try to access buffer+100.. and propably get a segfault, except if it finds a null byte before it reaches unaccessed memory.
Also if the user enters more than 100 bytes, and the null byte is the 101th byte (let's suppose that) then 100 bytes will be written to the array and printf() won't find the null byte in those 100 elements of buffer.
2) If what the user enters contains format indentifiers, printf() will print things from the stack.
Solution?

int main() {
char buffer[100] = { 0 }; // zeroing all the elements of the array
fgets(buffer, 99, stdin);
printf("%s", buffer);
return 0;
}


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List