Skip to content

Commit 4565682

Browse files
Replaced all the functions with int64_t instead of int
Functions that have replaced with int64_t: modulo, bitwise or, bitwise and, memory and execution loops. For example: This truly fixes the overflow issue on modulo operators while using very high values, e.g. flexi's space voyage
1 parent 612afc4 commit 4565682

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

projectm-eval/TreeFunctions.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ prjm_eval_function_decl(execute_loop)
265265
PRJM_EVAL_F* value_ptr = &ctx->value;
266266
invoke_arg(0, &value_ptr);
267267

268-
int loop_count_int = (int) (*value_ptr);
268+
int64_t loop_count_int = (int64_t) (*value_ptr);
269269
/* Limit execution count */
270270
if (loop_count_int > MAX_LOOP_COUNT)
271271
{
272272
loop_count_int = MAX_LOOP_COUNT;
273273
}
274274

275-
for (int i = 0; i < loop_count_int; i++)
275+
for (int64_t i = 0; i < loop_count_int; i++)
276276
{
277277
ctx->value = .0;
278278
value_ptr = &ctx->value;
@@ -288,7 +288,7 @@ prjm_eval_function_decl(execute_while)
288288

289289
ctx->value = .0;
290290
PRJM_EVAL_F* value_ptr = &ctx->value;
291-
int loop_count_int = MAX_LOOP_COUNT;
291+
int64_t loop_count_int = MAX_LOOP_COUNT;
292292
do
293293
{
294294
invoke_arg(0, &value_ptr);
@@ -361,7 +361,7 @@ prjm_eval_function_decl(mem)
361361
invoke_arg(0, &index_ptr);
362362

363363
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
364-
PRJM_EVAL_F* mem_addr = prjm_eval_memory_allocate(ctx->memory_buffer, (int) (*index_ptr + 0.0001));
364+
PRJM_EVAL_F* mem_addr = prjm_eval_memory_allocate(ctx->memory_buffer, (int64_t) (*index_ptr + 0.0001));
365365
if (mem_addr)
366366
{
367367
assign_ret_ref(mem_addr);
@@ -379,7 +379,7 @@ prjm_eval_function_decl(freembuf)
379379
invoke_arg(0, ret_val);
380380

381381
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
382-
prjm_eval_memory_free_block(ctx->memory_buffer, (int) (**ret_val + 0.0001));
382+
prjm_eval_memory_free_block(ctx->memory_buffer, (int64_t) (**ret_val + 0.0001));
383383
}
384384

385385
prjm_eval_function_decl(memcpy)
@@ -601,13 +601,13 @@ prjm_eval_function_decl(mod)
601601
invoke_arg(0, &val1_ptr);
602602
invoke_arg(1, &val2_ptr);
603603

604-
int divisor = (int) *val2_ptr;
604+
int64_t divisor = (int64_t) *val2_ptr;
605605
if (divisor == 0)
606606
{
607607
assign_ret_val(0.0);
608608
return;
609609
}
610-
assign_ret_val((PRJM_EVAL_F) ((int) *val1_ptr % divisor));
610+
assign_ret_val((PRJM_EVAL_F) ((int64_t) *val1_ptr % divisor));
611611
}
612612

613613
prjm_eval_function_decl(boolean_and_op)
@@ -776,7 +776,7 @@ prjm_eval_function_decl(bitwise_or_op)
776776
invoke_arg(0, ret_val);
777777
invoke_arg(1, &val2_ptr);
778778

779-
assign_ret_val((PRJM_EVAL_F) ((int)(**ret_val) | (int)(*val2_ptr)));
779+
assign_ret_val((PRJM_EVAL_F) ((int64_t)(**ret_val) | (int64_t)(*val2_ptr)));
780780
}
781781

782782
prjm_eval_function_decl(bitwise_or)
@@ -791,7 +791,7 @@ prjm_eval_function_decl(bitwise_or)
791791
invoke_arg(0, &val1_ptr);
792792
invoke_arg(1, &val2_ptr);
793793

794-
assign_ret_val((PRJM_EVAL_F) ((int)(*val1_ptr) | (int)(*val2_ptr)));
794+
assign_ret_val((PRJM_EVAL_F) ((int64_t)(*val1_ptr) | (int64_t)(*val2_ptr)));
795795
}
796796

797797
prjm_eval_function_decl(bitwise_and_op)
@@ -804,7 +804,7 @@ prjm_eval_function_decl(bitwise_and_op)
804804
invoke_arg(0, ret_val);
805805
invoke_arg(1, &val2_ptr);
806806

807-
assign_ret_val((PRJM_EVAL_F) ((int)(**ret_val) & (int)(*val2_ptr)));
807+
assign_ret_val((PRJM_EVAL_F) ((int64_t)(**ret_val) & (int64_t)(*val2_ptr)));
808808
}
809809

810810
prjm_eval_function_decl(bitwise_and)
@@ -819,7 +819,7 @@ prjm_eval_function_decl(bitwise_and)
819819
invoke_arg(0, &val1_ptr);
820820
invoke_arg(1, &val2_ptr);
821821

822-
assign_ret_val((PRJM_EVAL_F) ((int)(*val1_ptr) & (int)(*val2_ptr)));
822+
assign_ret_val((PRJM_EVAL_F) ((int64_t)(*val1_ptr) & (int64_t)(*val2_ptr)));
823823
}
824824

825825
prjm_eval_function_decl(mod_op)
@@ -832,13 +832,13 @@ prjm_eval_function_decl(mod_op)
832832
invoke_arg(0, ret_val);
833833
invoke_arg(1, &val2_ptr);
834834

835-
int divisor = (int) *val2_ptr;
835+
int64_t divisor = (int64_t) *val2_ptr;
836836
if (divisor == 0)
837837
{
838838
assign_ret_val(0.0);
839839
return;
840840
}
841-
assign_ret_val((PRJM_EVAL_F) ((int)(**ret_val) % divisor));
841+
assign_ret_val((PRJM_EVAL_F) ((int64_t)(**ret_val) % divisor));
842842
}
843843

844844
prjm_eval_function_decl(pow_op)

0 commit comments

Comments
 (0)