Skip to content

Instantly share code, notes, and snippets.

@gnosek
Created March 3, 2018 12:35
Show Gist options
  • Save gnosek/21b620a03c2e43bfd77549e29638fed1 to your computer and use it in GitHub Desktop.
Save gnosek/21b620a03c2e43bfd77549e29638fed1 to your computer and use it in GitHub Desktop.
/*
blackfire@angua:~/src$ make t
cc t.c -o t
blackfire@angua:~/src$ ./t
&arr[0] = 0x7fdebb404b60; arr[0] = 0
&arr[1] = 0x7fdebb404b61; arr[1] = 1
&arr[2] = 0x7fdebb404b62; arr[2] = 2
&arr[3] = 0x7fdebb404b63; arr[3] = 3
&arr[4] = 0x7fdebb404b64; arr[4] = 4
&arr[5] = 0x7fdebb404b65; arr[5] = 5
&arr[6] = 0x7fdebb404b66; arr[6] = 6
&arr[7] = 0x7fdebb404b67; arr[7] = 7
&arr[8] = 0x7fdebb404b68; arr[8] = 8
&arr[9] = 0x7fdebb404b69; arr[9] = 9
&arr[10] = 0x7fdebb404b6a; arr[10] = 10
&arr[11] = 0x7fdebb404b6b; arr[11] = 11
&arr[12] = 0x7fdebb404b6c; arr[12] = 12
&arr[13] = 0x7fdebb404b6d; arr[13] = 13
&arr[14] = 0x7fdebb404b6e; arr[14] = 14
&arr[15] = 0x7fdebb404b6f; arr[15] = 15
&arr[16] = 0x7fdebb404b70; arr[16] = 16
&arr[17] = 0x7fdebb404b71; arr[17] = 17
&arr[18] = 0x7fdebb404b72; arr[18] = 18
&arr[19] = 0x7fdebb404b73; arr[19] = 19
blackfire@angua:~/src$ cat t.c
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main()
{
void* v = malloc(44);
int i;
for(i=0; i<20; i++){
uint8_t* arr = (uint8_t*)v;
*(arr+i) = i;
}
uint8_t* arr = (uint8_t*)v;
for(i=0; i<20; i++){
printf("&arr[%d] = %p; arr[%d] = %d\n", i, arr+i, i, arr[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment