summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-08-28 11:29:58 +0800
committerIru Cai <mytbk920423@gmail.com>2018-08-28 11:33:58 +0800
commit98d8ab338e1a662966bebad95fdd8c07cecbe070 (patch)
tree58a2b96f230d8995d2809cc19ec09a383af4d733
parent44dd43bd73af28df7bd7afd8374c0a449cea6870 (diff)
downloadrich4-98d8ab338e1a662966bebad95fdd8c07cecbe070.tar.xz
allocate_some_struct
-rw-r--r--csrc/data_struct.c (renamed from csrc/buggy_func.c)24
-rw-r--r--csrc/data_struct.h11
2 files changed, 24 insertions, 11 deletions
diff --git a/csrc/buggy_func.c b/csrc/data_struct.c
index a963b33..53d8cd3 100644
--- a/csrc/buggy_func.c
+++ b/csrc/data_struct.c
@@ -1,19 +1,21 @@
-struct st
-{
- int16_t f0;
- int16_t f2;
- int16_t f4;
- int16_t f6;
- int16_t * f8;
- int16_t data[0];
-};
-
static inline mem_copy_words(void *dst, void *src, size_t n)
{
memcpy(dst, src, n*2);
}
-int fcn_00451a97(struct st *a1, struct st *a2, int a3, int a4, int a5, int a6)
+struct st * allocate_some_struct(int a1, int a2, int a3, int a4)
+{
+ struct st * newst = (struct st *)malloc(a1 * a2 * 2 + 12);
+ newst->f0 = a1;
+ newst->f2 = a2;
+ newst->f4 = a3;
+ newst->f6 = a4;
+ newst->f8 = newst->data;
+}
+
+/* this function looks buggy and can crash the game */
+
+struct st * fcn_00451a97(struct st *a1, struct st *a2, int a3, int a4, int a5, int a6)
{
if (a2 == NULL) {
a2 = malloc(a5 * a6 * 2 + 12);
diff --git a/csrc/data_struct.h b/csrc/data_struct.h
new file mode 100644
index 0000000..2fa06e9
--- /dev/null
+++ b/csrc/data_struct.h
@@ -0,0 +1,11 @@
+struct st
+{
+ int16_t f0;
+ int16_t f2;
+ int16_t f4;
+ int16_t f6;
+ int16_t * f8;
+ int16_t data[0];
+};
+
+struct st * allocate_some_struct(int a1, int a2, int a3, int a4);