Skip to content

Instantly share code, notes, and snippets.

@Scrappers-glitch
Last active March 27, 2023 23:23
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 Scrappers-glitch/dd327e9e8e9dfed1ea06e76de56b9f42 to your computer and use it in GitHub Desktop.
Save Scrappers-glitch/dd327e9e8e9dfed1ea06e76de56b9f42 to your computer and use it in GitHub Desktop.
Test void* to jlong implicit type-conversion.
#include <stdio.h>
#include <stdlib.h>
/* define a non-system-specific pointer type that can hold an address of up-to 8-bytes */
typedef long long jlong;
jlong Java_util_getAddress() {
int* x = malloc(sizeof(int));
*x = 2312;
void* address = x;
return address;
}
int main() {
int* ptr = ((int*) Java_util_getAddress());
printf("%lld\n", *((int*) Java_util_getAddress()));
printf("%lld\n", *((int*) Java_util_getAddress()));
free(ptr);
printf("%lld\n", *((int*) Java_util_getAddress()));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment