Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/bcmath: Fixed pointer subtraction for scale #17986

Open
wants to merge 3 commits into
base: PHP-8.4
Choose a base branch
from

Conversation

SakiTakamachi
Copy link
Member

No description provided.

@SakiTakamachi SakiTakamachi marked this pull request as ready for review March 7, 2025 05:42
@nielsdos
Copy link
Member

nielsdos commented Mar 7, 2025

Right, do you have a test?

@SakiTakamachi
Copy link
Member Author

@nielsdos
I've been trying all sorts of things, but I haven't found any code that's affected by this yet...

@SakiTakamachi
Copy link
Member Author

Since this is the code for when auto_scale is false, only bccomp() is affected.

In the following code, scale is set to 20, but is only initialized to 10.

bccomp('0.0000000000000000000000001', '0', 10);

However, since only values ​​up to scale 10 are used for comparison, there will be no erroneous results.
It just allocates extra memory that is never used.

@@ -180,7 +180,7 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, siz
*/
if (str_scale > 0) {
const char *fractional_new_end = bc_skip_zero_reverse(fractional_end, fractional_ptr);
str_scale -= fractional_new_end - fractional_end;
str_scale -= fractional_end - fractional_new_end; // fractional_end >= fractional_new_end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use c-style comments, i.e. /* */

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems logical

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

Successfully merging this pull request may close these issues.

3 participants