I wanted to test a my idea about function pointers. I wrote a test but it doesn't work(causes a Segmentation fault). Here is my test simplified:
#include<stdlib.h>
void a(){}
void b(){}
int main(){
size_t s=0;
char* p1=(char*)&a;
char* p2=(char*)&b;
while(*p1++==*p2++) s++;
void (*o)();
char* c=malloc(s);
while(s--) *(c+s)=*((char*)&a+s);
o=(void(*)())c;
o();
return 0;
}
The code should copy machine code of an empty function(here if finds the intersection of data at the addresses of two empty function and copies that) and run the copy.
Thanks for reaching out.

s > 0? And why do you think you can run arbitrary machine code allocated in data memory? Did you hear about modern protection schemes?