Last active
February 25, 2017 08:20
-
-
Save technion/a16095fa6e3a027d6bc938ad6f9bdc50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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