24.12.2012 Views

CSC322 C Programming and UNIX - Department of Computer ...

CSC322 C Programming and UNIX - Department of Computer ...

CSC322 C Programming and UNIX - Department of Computer ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

void* secure_malloc(int size)<br />

{<br />

void* res = malloc(size);<br />

}<br />

Example (2)<br />

if(!res)<br />

{<br />

fprintf(stderr, "malloc() failure -- out <strong>of</strong> memory?");<br />

exit(EXIT_FAILURE);<br />

}<br />

return res;<br />

char* secure_strdup(char* source)<br />

{<br />

void* res = secure_malloc(strlen(source)+1);<br />

}<br />

strcpy(res, source);<br />

return res;<br />

Stephan Schulz 616

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!