Skip to content

Commit f13d541

Browse files
authored
Fix GCC 12 compiler warnings (php#10713)
* Fix -Wunused-but-set-variable compiler warning in ext/mysqli * Fix -Wstrict-prototypes compiler warning in ext/mysqlnd * Fix -Wstrict-prototypes compiler warning in ext/soap * Fix -Wunused-but-set-variable compiler warning in ext/exif However, this code looks really sketchy... * Fix -Wstrict-prototypes compiler warning in ext/openssl * Fix -Wstrict-prototypes compiler warning in ext/dba Add void to our bundled libraries * Refactor bundled BCMath library Fix -Wdeprecated-non-prototype compiler warnings Use bool instead of char/int Cleanup some useless header includes
1 parent 02ec4c5 commit f13d541

26 files changed

+71
-161
lines changed

ext/bcmath/libbcmath/src/add.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
N1 is added to N2 and the result placed into RESULT. SCALE_MIN
4343
is the minimum scale for the result. */
4444

45-
void
46-
bc_add (n1, n2, result, scale_min)
47-
bc_num n1, n2, *result;
48-
int scale_min;
45+
void bc_add (bc_num n1, bc_num n2, bc_num *result, int scale_min)
4946
{
5047
bc_num sum = NULL;
5148
int cmp_res;

ext/bcmath/libbcmath/src/bcmath.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ typedef struct bc_struct
5555
#include "config.h"
5656
#endif
5757

58-
#include "php.h"
58+
#include <stdbool.h>
59+
#include "php.h" /* Needed for safe_pemalloc() in init.c */
5960
#include "../../php_bcmath.h"
6061

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

113114
char bc_is_zero_for_scale(bc_num num, int scale);
114115

115-
char bc_is_near_zero(bc_num num, int scale);
116+
bool bc_is_near_zero(bc_num num, int scale);
116117

117-
char bc_is_neg(bc_num num);
118+
bool bc_is_neg(bc_num num);
118119

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

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

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

135-
int bc_sqrt(bc_num *num, int scale);
136+
bool bc_sqrt(bc_num *num, int scale);
136137

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

ext/bcmath/libbcmath/src/compare.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <stdlib.h>
3535
#include <ctype.h>
3636
#include <stdarg.h>
37+
#include <stdbool.h>
3738
#include "bcmath.h"
3839
#include "private.h"
3940

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

45-
int
46-
_bc_do_compare (n1, n2, use_sign, ignore_last)
47-
bc_num n1, n2;
48-
int use_sign;
49-
int ignore_last;
46+
int _bc_do_compare(bc_num n1, bc_num n2, bool use_sign, bool ignore_last)
5047
{
5148
char *n1ptr, *n2ptr;
5249
int count;
@@ -151,9 +148,7 @@ _bc_do_compare (n1, n2, use_sign, ignore_last)
151148

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

154-
int
155-
bc_compare (n1, n2)
156-
bc_num n1, n2;
151+
int bc_compare(bc_num n1, bc_num n2)
157152
{
158-
return _bc_do_compare (n1, n2, TRUE, FALSE);
153+
return _bc_do_compare (n1, n2, true, false);
159154
}

ext/bcmath/libbcmath/src/div.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ static void _one_mult (unsigned char *num, int size, int digit, unsigned char *r
7979
digits after the decimal point is SCALE. It returns -1 if division
8080
by zero is tried. The algorithm is found in Knuth Vol 2. p237. */
8181

82-
int
83-
bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale)
82+
int bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale)
8483
{
8584
bc_num qval;
8685
unsigned char *num1, *num2;

ext/bcmath/libbcmath/src/divmod.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
is NULL then that store will be omitted.
4444
*/
4545

46-
int
47-
bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale)
46+
int bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale)
4847
{
4948
bc_num quotient = NULL;
5049
bc_num temp;
@@ -78,8 +77,7 @@ bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale)
7877
/* Modulo for numbers. This computes NUM1 % NUM2 and puts the
7978
result in RESULT. */
8079

81-
int
82-
bc_modulo (bc_num num1, bc_num num2, bc_num *result, int scale)
80+
int bc_modulo (bc_num num1, bc_num num2, bc_num *result, int scale)
8381
{
8482
return bc_divmod (num1, num2, NULL, result, scale);
8583
}

ext/bcmath/libbcmath/src/doaddsub.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
returned. The signs of N1 and N2 are ignored.
4343
SCALE_MIN is to set the minimum scale of the result. */
4444

45-
bc_num
46-
_bc_do_add (n1, n2, scale_min)
47-
bc_num n1, n2;
48-
int scale_min;
45+
bc_num _bc_do_add(bc_num n1, bc_num n2, int scale_min)
4946
{
5047
bc_num sum;
5148
int sum_scale, sum_digits;
@@ -134,10 +131,7 @@ _bc_do_add (n1, n2, scale_min)
134131
assumed to be larger than N2. SCALE_MIN is the minimum scale
135132
of the result. */
136133

137-
bc_num
138-
_bc_do_sub (n1, n2, scale_min)
139-
bc_num n1, n2;
140-
int scale_min;
134+
bc_num _bc_do_sub(bc_num n1, bc_num n2, int scale_min)
141135
{
142136
bc_num diff;
143137
int diff_scale, diff_len;

ext/bcmath/libbcmath/src/init.c

+5-13
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939

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

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

64-
void
65-
_bc_free_num_ex (num, persistent)
66-
bc_num *num;
67-
int persistent;
62+
void _bc_free_num_ex(bc_num *num, int persistent)
6863
{
6964
if (*num == NULL) return;
7065
(*num)->n_refs--;
@@ -80,8 +75,7 @@ _bc_free_num_ex (num, persistent)
8075

8176
/* Initialize the number package! */
8277

83-
void
84-
bc_init_numbers (void)
78+
void bc_init_numbers(void)
8579
{
8680
BCG(_zero_) = _bc_new_num_ex (1,0,1);
8781
BCG(_one_) = _bc_new_num_ex (1,0,1);
@@ -93,8 +87,7 @@ bc_init_numbers (void)
9387

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

96-
bc_num
97-
bc_copy_num (bc_num num)
90+
bc_num bc_copy_num(bc_num num)
9891
{
9992
num->n_refs++;
10093
return num;
@@ -103,8 +96,7 @@ bc_copy_num (bc_num num)
10396

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

106-
void
107-
bc_init_num (bc_num *num)
99+
void bc_init_num(bc_num *num)
108100
{
109101
*num = bc_copy_num (BCG(_zero_));
110102
}

ext/bcmath/libbcmath/src/int2num.c

+1-9
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,12 @@
3030
*************************************************************************/
3131

3232
#include <config.h>
33-
#include <stdio.h>
34-
#include <stdlib.h>
35-
#include <ctype.h>
36-
#include <stdarg.h>
3733
#include "bcmath.h"
38-
#include "private.h"
3934

4035

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

43-
void
44-
bc_int2num (num, val)
45-
bc_num *num;
46-
int val;
38+
void bc_int2num(bc_num *num, int val)
4739
{
4840
char buffer[30];
4941
char *bptr, *vptr;

ext/bcmath/libbcmath/src/nearzero.c

+4-12
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,14 @@
2929
3030
*************************************************************************/
3131

32-
#include <config.h>
33-
#include <stdio.h>
34-
#include <stdlib.h>
35-
#include <ctype.h>
36-
#include <stdarg.h>
32+
#include <stdbool.h>
3733
#include "bcmath.h"
38-
#include "private.h"
3934

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

44-
char
45-
bc_is_near_zero (num, scale)
46-
bc_num num;
47-
int scale;
39+
bool bc_is_near_zero(bc_num num, int scale)
4840
{
4941
int count;
5042
char *nptr;
@@ -61,7 +53,7 @@ bc_is_near_zero (num, scale)
6153
while ((count > 0) && (*nptr++ == 0)) count--;
6254

6355
if (count != 0 && (count != 1 || *--nptr != 1))
64-
return FALSE;
56+
return false;
6557
else
66-
return TRUE;
58+
return true;
6759
}

ext/bcmath/libbcmath/src/neg.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,11 @@
2929
3030
*************************************************************************/
3131

32-
#include <config.h>
33-
#include <stdio.h>
34-
#include <stdlib.h>
35-
#include <ctype.h>
36-
#include <stdarg.h>
32+
#include <stdbool.h>
3733
#include "bcmath.h"
38-
#include "private.h"
3934

4035
/* In some places we need to check if the number is negative. */
41-
42-
char
43-
bc_is_neg (num)
44-
bc_num num;
36+
bool bc_is_neg(bc_num num)
4537
{
4638
return num->n_sign == MINUS;
4739
}

ext/bcmath/libbcmath/src/num2long.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,14 @@
3030
*************************************************************************/
3131

3232
#include <config.h>
33-
#include <stdio.h>
34-
#include <stdlib.h>
35-
#include <ctype.h>
36-
#include <stdarg.h>
3733
#include "bcmath.h"
38-
#include "private.h"
3934

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

45-
long
46-
bc_num2long (num)
47-
bc_num num;
40+
long bc_num2long(bc_num num)
4841
{
4942
long val;
5043
char *nptr;

ext/bcmath/libbcmath/src/num2str.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939

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

42-
zend_string
43-
*bc_num2str_ex (num, scale)
44-
bc_num num;
45-
int scale;
42+
zend_string *bc_num2str_ex(bc_num num, int scale)
4643
{
4744
zend_string *str;
4845
char *sptr;

ext/bcmath/libbcmath/src/private.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
/* "Private" routines to bcmath. */
3333

34+
#include <stdbool.h>
35+
3436
/* routines */
35-
int _bc_do_compare (bc_num n1, bc_num n2, int use_sign, int ignore_last);
37+
int _bc_do_compare (bc_num n1, bc_num n2, bool use_sign, bool ignore_last);
3638
bc_num _bc_do_add (bc_num n1, bc_num n2, int scale_min);
3739
bc_num _bc_do_sub (bc_num n1, bc_num n2, int scale_min);
3840
void _bc_rm_leading_zeros (bc_num num);

ext/bcmath/libbcmath/src/recmul.c

-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030
*************************************************************************/
3131

3232
#include <config.h>
33-
#include <stdio.h>
3433
#include <assert.h>
35-
#include <stdlib.h>
36-
#include <ctype.h>
37-
#include <stdarg.h>
3834
#include "bcmath.h"
3935
#include "private.h"
4036

ext/bcmath/libbcmath/src/rmzero.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,14 @@
3030
*************************************************************************/
3131

3232
#include <config.h>
33-
#include <stdio.h>
34-
#include <stdlib.h>
35-
#include <ctype.h>
36-
#include <stdarg.h>
3733
#include "bcmath.h"
3834
#include "private.h"
3935

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

44-
void
45-
_bc_rm_leading_zeros (num)
46-
bc_num num;
40+
void _bc_rm_leading_zeros(bc_num num)
4741
{
4842
/* We can move n_value to point to the first non zero digit! */
4943
while (*num->n_value == 0 && num->n_len > 1) {

0 commit comments

Comments
 (0)