add max component

This commit is contained in:
hugogogo
2026-05-26 15:14:28 +02:00
parent abc5754bba
commit 487191c516
4 changed files with 31 additions and 8 deletions

View File

@@ -13,7 +13,9 @@
*/
#define DOUBLE_PRECISION 0.00001
#define MAX_EXPONENT 1000
// maximum exponent supported to avoid excessive variable-length stack allocation (VLA),
// which can lead to stack overflows, segmentation faults, and potential denial-of-service (DoS)
#define MAX_EXPONENT 1024
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MAIN.C

View File

@@ -62,6 +62,8 @@ static int get_number_of_exponents(s_term *terms, int max_exponent)
int i;
int nbr_of_exponent;
if (max_exponent <= 0 || max_exponent > MAX_EXPONENT)
stop_errors("max_exponent should be between 0 and %d, but got : %d\n", MAX_EXPONENT, max_exponent);
int exponent_present[max_exponent];
ft_bzero(exponent_present, sizeof(exponent_present));

View File

@@ -194,7 +194,7 @@ static int get_exponent(s_token *tokens, int i, int *token_count)
ret_exponent = 0;
}
// check if exponent is not too big, to avoid overflow when calculating power
// check if exponent is not too big
if (ret_exponent > MAX_EXPONENT)
{
stop_errors("exponent is too big (max supported exponent is %d), got : %d\n", MAX_EXPONENT, ret_exponent);

File diff suppressed because one or more lines are too long