Skip to content

Instantly share code, notes, and snippets.

@technion
Last active February 25, 2017 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technion/a16095fa6e3a027d6bc938ad6f9bdc50 to your computer and use it in GitHub Desktop.
Save technion/a16095fa6e3a027d6bc938ad6f9bdc50 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
int returnsnegative() {
return -5;
}
ssize_t my_write(int fd, const void *buf, size_t count) {
/* This functions has the same function prototype as write() */
/* For more information: https://linux.die.net/man/2/write */
printf("We have a count of %zu and will write that many characters\n", count
);
return 0; /* Return is irrelevant */
}
int main() {
/* Simulation of the given code */
int length = returnsnegative(); /* This is "the bug", where apparently
* negative numbers appear
*/
my_write(0, "string", length);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment