Skip to content

Fix GCC 12 compiler warnings #10713

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

Merged
merged 7 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ext/bcmath/libbcmath/src/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
N1 is added to N2 and the result placed into RESULT. SCALE_MIN
is the minimum scale for the result. */

void
bc_add (n1, n2, result, scale_min)
bc_num n1, n2, *result;
int scale_min;
void bc_add (bc_num n1, bc_num n2, bc_num *result, int scale_min)
{
bc_num sum = NULL;
int cmp_res;
Expand Down
9 changes: 5 additions & 4 deletions ext/bcmath/libbcmath/src/bcmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ typedef struct bc_struct
#include "config.h"
#endif

#include "php.h"
#include <stdbool.h>
#include "php.h" /* Needed for safe_pemalloc() in init.c */
#include "../../php_bcmath.h"

/* The base used in storing the numbers in n_value above.
Expand Down Expand Up @@ -112,9 +113,9 @@ char bc_is_zero(bc_num num);

char bc_is_zero_for_scale(bc_num num, int scale);

char bc_is_near_zero(bc_num num, int scale);
bool bc_is_near_zero(bc_num num, int scale);

char bc_is_neg(bc_num num);
bool bc_is_neg(bc_num num);

void bc_add(bc_num n1, bc_num n2, bc_num *result, int scale_min);

Expand All @@ -132,7 +133,7 @@ int bc_raisemod(bc_num base, bc_num expo, bc_num mo, bc_num *result, int scale);

void bc_raise(bc_num num1, bc_num num2, bc_num *resul, int scale);

int bc_sqrt(bc_num *num, int scale);
bool bc_sqrt(bc_num *num, int scale);

void bc_out_num(bc_num num, int o_base, void (* out_char)(char), int leading_zero);

Expand Down
13 changes: 4 additions & 9 deletions ext/bcmath/libbcmath/src/compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include "bcmath.h"
#include "private.h"

Expand All @@ -42,11 +43,7 @@
than N2 and +1 if N1 is greater than N2. If USE_SIGN is false, just
compare the magnitudes. */

int
_bc_do_compare (n1, n2, use_sign, ignore_last)
bc_num n1, n2;
int use_sign;
int ignore_last;
int _bc_do_compare(bc_num n1, bc_num n2, bool use_sign, bool ignore_last)
{
char *n1ptr, *n2ptr;
int count;
Expand Down Expand Up @@ -151,9 +148,7 @@ _bc_do_compare (n1, n2, use_sign, ignore_last)

/* This is the "user callable" routine to compare numbers N1 and N2. */

int
bc_compare (n1, n2)
bc_num n1, n2;
int bc_compare(bc_num n1, bc_num n2)
{
return _bc_do_compare (n1, n2, TRUE, FALSE);
return _bc_do_compare (n1, n2, true, false);
}
3 changes: 1 addition & 2 deletions ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ static void _one_mult (unsigned char *num, int size, int digit, unsigned char *r
digits after the decimal point is SCALE. It returns -1 if division
by zero is tried. The algorithm is found in Knuth Vol 2. p237. */

int
bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale)
int bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale)
{
bc_num qval;
unsigned char *num1, *num2;
Expand Down
6 changes: 2 additions & 4 deletions ext/bcmath/libbcmath/src/divmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
is NULL then that store will be omitted.
*/

int
bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale)
int bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale)
{
bc_num quotient = NULL;
bc_num temp;
Expand Down Expand Up @@ -78,8 +77,7 @@ bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale)
/* Modulo for numbers. This computes NUM1 % NUM2 and puts the
result in RESULT. */

int
bc_modulo (bc_num num1, bc_num num2, bc_num *result, int scale)
int bc_modulo (bc_num num1, bc_num num2, bc_num *result, int scale)
{
return bc_divmod (num1, num2, NULL, result, scale);
}
10 changes: 2 additions & 8 deletions ext/bcmath/libbcmath/src/doaddsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
returned. The signs of N1 and N2 are ignored.
SCALE_MIN is to set the minimum scale of the result. */

bc_num
_bc_do_add (n1, n2, scale_min)
bc_num n1, n2;
int scale_min;
bc_num _bc_do_add(bc_num n1, bc_num n2, int scale_min)
{
bc_num sum;
int sum_scale, sum_digits;
Expand Down Expand Up @@ -134,10 +131,7 @@ _bc_do_add (n1, n2, scale_min)
assumed to be larger than N2. SCALE_MIN is the minimum scale
of the result. */

bc_num
_bc_do_sub (n1, n2, scale_min)
bc_num n1, n2;
int scale_min;
bc_num _bc_do_sub(bc_num n1, bc_num n2, int scale_min)
{
bc_num diff;
int diff_scale, diff_len;
Expand Down
18 changes: 5 additions & 13 deletions ext/bcmath/libbcmath/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@

/* new_num allocates a number and sets fields to known values. */

bc_num
_bc_new_num_ex (length, scale, persistent)
int length, scale, persistent;
bc_num _bc_new_num_ex (int length, int scale, int persistent)
{
bc_num temp;
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
Expand All @@ -61,10 +59,7 @@ _bc_new_num_ex (length, scale, persistent)
/* "Frees" a bc_num NUM. Actually decreases reference count and only
frees the storage if reference count is zero. */

void
_bc_free_num_ex (num, persistent)
bc_num *num;
int persistent;
void _bc_free_num_ex(bc_num *num, int persistent)
{
if (*num == NULL) return;
(*num)->n_refs--;
Expand All @@ -80,8 +75,7 @@ _bc_free_num_ex (num, persistent)

/* Initialize the number package! */

void
bc_init_numbers (void)
void bc_init_numbers(void)
{
BCG(_zero_) = _bc_new_num_ex (1,0,1);
BCG(_one_) = _bc_new_num_ex (1,0,1);
Expand All @@ -93,8 +87,7 @@ bc_init_numbers (void)

/* Make a copy of a number! Just increments the reference count! */

bc_num
bc_copy_num (bc_num num)
bc_num bc_copy_num(bc_num num)
{
num->n_refs++;
return num;
Expand All @@ -103,8 +96,7 @@ bc_copy_num (bc_num num)

/* Initialize a number NUM by making it a copy of zero. */

void
bc_init_num (bc_num *num)
void bc_init_num(bc_num *num)
{
*num = bc_copy_num (BCG(_zero_));
}
10 changes: 1 addition & 9 deletions ext/bcmath/libbcmath/src/int2num.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,12 @@
*************************************************************************/

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include "bcmath.h"
#include "private.h"


/* Convert an integer VAL to a bc number NUM. */

void
bc_int2num (num, val)
bc_num *num;
int val;
void bc_int2num(bc_num *num, int val)
{
char buffer[30];
char *bptr, *vptr;
Expand Down
16 changes: 4 additions & 12 deletions ext/bcmath/libbcmath/src/nearzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@

*************************************************************************/

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include "bcmath.h"
#include "private.h"

/* In some places we need to check if the number NUM is almost zero.
Specifically, all but the last digit is 0 and the last digit is 1.
Last digit is defined by scale. */

char
bc_is_near_zero (num, scale)
bc_num num;
int scale;
bool bc_is_near_zero(bc_num num, int scale)
{
int count;
char *nptr;
Expand All @@ -61,7 +53,7 @@ bc_is_near_zero (num, scale)
while ((count > 0) && (*nptr++ == 0)) count--;

if (count != 0 && (count != 1 || *--nptr != 1))
return FALSE;
return false;
else
return TRUE;
return true;
}
12 changes: 2 additions & 10 deletions ext/bcmath/libbcmath/src/neg.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@

*************************************************************************/

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include "bcmath.h"
#include "private.h"

/* In some places we need to check if the number is negative. */

char
bc_is_neg (num)
bc_num num;
bool bc_is_neg(bc_num num)
{
return num->n_sign == MINUS;
}
9 changes: 1 addition & 8 deletions ext/bcmath/libbcmath/src/num2long.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,14 @@
*************************************************************************/

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include "bcmath.h"
#include "private.h"

/* Convert a number NUM to a long. The function returns only the integer
part of the number. For numbers that are too large to represent as
a long, this function returns a zero. This can be detected by checking
the NUM for zero after having a zero returned. */

long
bc_num2long (num)
bc_num num;
long bc_num2long(bc_num num)
{
long val;
char *nptr;
Expand Down
5 changes: 1 addition & 4 deletions ext/bcmath/libbcmath/src/num2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@

/* Convert a numbers to a string. Base 10 only.*/

zend_string
*bc_num2str_ex (num, scale)
bc_num num;
int scale;
zend_string *bc_num2str_ex(bc_num num, int scale)
{
zend_string *str;
char *sptr;
Expand Down
4 changes: 3 additions & 1 deletion ext/bcmath/libbcmath/src/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

/* "Private" routines to bcmath. */

#include <stdbool.h>

/* routines */
int _bc_do_compare (bc_num n1, bc_num n2, int use_sign, int ignore_last);
int _bc_do_compare (bc_num n1, bc_num n2, bool use_sign, bool ignore_last);
bc_num _bc_do_add (bc_num n1, bc_num n2, int scale_min);
bc_num _bc_do_sub (bc_num n1, bc_num n2, int scale_min);
void _bc_rm_leading_zeros (bc_num num);
4 changes: 0 additions & 4 deletions ext/bcmath/libbcmath/src/recmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
*************************************************************************/

#include <config.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include "bcmath.h"
#include "private.h"

Expand Down
8 changes: 1 addition & 7 deletions ext/bcmath/libbcmath/src/rmzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@
*************************************************************************/

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include "bcmath.h"
#include "private.h"

/* For many things, we may have leading zeros in a number NUM.
_bc_rm_leading_zeros just moves the data "value" pointer to the
correct place and adjusts the length. */

void
_bc_rm_leading_zeros (num)
bc_num num;
void _bc_rm_leading_zeros(bc_num num)
{
/* We can move n_value to point to the first non zero digit! */
while (*num->n_value == 0 && num->n_len > 1) {
Expand Down
Loading