Skip to content

Instantly share code, notes, and snippets.

@dobrokot
Created April 16, 2015 23:51
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 dobrokot/61959f21609abdea0960 to your computer and use it in GitHub Desktop.
Save dobrokot/61959f21609abdea0960 to your computer and use it in GitHub Desktop.
#include <string.h>
#include <stdio.h>
typedef char *p;
volatile p src = NULL;
volatile p dst = NULL;
volatile size_t n = 0;
#define TEST(x) if (x) ; else { printf("error, %s\n", #x); }
int main() {
TEST(dst == memcpy(dst, src, n));
TEST(dst == memmove(dst, src, n));
TEST(dst == strncpy(dst, src, n));
TEST(dst == memset(dst, 0, n));
TEST(0 == strncmp(src, dst, n));
TEST(0 == memcmp(src, dst, n));
/* Observable effect after observable reads from 'volatile n'.
OS are not always give explicit message
about segmentation fault/invalid read at process termination. */
printf("Still alive. Still alive.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment