Skip to content

Instantly share code, notes, and snippets.

@scotchi
Created April 17, 2020 11:18
Show Gist options
  • Save scotchi/5b07056855220f9170bda5afeac5b64c to your computer and use it in GitHub Desktop.
Save scotchi/5b07056855220f9170bda5afeac5b64c to your computer and use it in GitHub Desktop.
A demonstration of the hack needed to pull a (not-always-going-to-be-valid) pointer out of P_SRCTRACK
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int foo;
int bar;
} MediaTrack;
typedef union {
long l;
double d;
void *p;
} ReaperReturn;
double what_reaper_actually_does()
{
MediaTrack *track = malloc(sizeof(MediaTrack));
return (long) track;
}
ReaperReturn what_reaper_should_do()
{
ReaperReturn ret;
MediaTrack *track = malloc(sizeof(MediaTrack));
ret.p = track;
return ret;
}
int main(int argc, const char *argv[])
{
double d = what_reaper_actually_does();
ReaperReturn r = what_reaper_should_do();
printf("what_reaper_actually_does: %ld, %f, %p\n"
"what_reaper_should_do: %ld, %f, %p\n",
(long) d, d, *(void **)(&d),
r.l, r.d, r.p);
return 0;
}
@scotchi
Copy link
Author

scotchi commented Apr 17, 2020

There's the undocumented function GetSetTrackSendInfo which returns a void * which should absolutely be used instead of this insanity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment