Skip to content

Instantly share code, notes, and snippets.

@thestinger
Last active May 21, 2017 19:16
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 thestinger/fd71418320ff5cf73cee271b284b4179 to your computer and use it in GitHub Desktop.
Save thestinger/fd71418320ff5cf73cee271b284b4179 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
int main() {
char *p = malloc(64);
if (!p)
return 1;
char *q = malloc(64);
if (!q)
return 1;
char a[64];
memset(p, 'a', 64);
memset(q, 'a', 64);
memset(a, 'a', 64);
size_t offset = p < q ? q - p : p - q;
p[offset + 32] = 'b';
printf("%.*s\n", 64, q);
offset = p < a ? a - p : p - a;
p[offset + 32] = 'b';
printf("%.*s\n", 64, a);
free(q);
free(p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment