Skip to content

Commit 5e745c7

Browse files
committed
Promote warnings to Errors in sockets's extension.
1 parent e8e09b6 commit 5e745c7

21 files changed

+306
-230
lines changed

ext/sockets/conversions.c

Lines changed: 113 additions & 58 deletions
Large diffs are not rendered by default.

ext/sockets/multicast.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out)
8787

8888
if (Z_TYPE_P(val) == IS_LONG) {
8989
if (Z_LVAL_P(val) < 0 || (zend_ulong)Z_LVAL_P(val) > UINT_MAX) {
90-
php_error_docref(NULL, E_WARNING,
91-
"The interface index cannot be negative or larger than %u;"
92-
" given " ZEND_LONG_FMT, UINT_MAX, Z_LVAL_P(val));
93-
ret = FAILURE;
94-
} else {
95-
*out = Z_LVAL_P(val);
96-
ret = SUCCESS;
90+
zend_value_error("The interface index cannot be negative or larger than %u; given " ZEND_LONG_FMT,
91+
UINT_MAX, Z_LVAL_P(val));
92+
return FAILURE;
9793
}
94+
*out = Z_LVAL_P(val);
95+
ret = SUCCESS;
9896
} else {
9997
zend_string *tmp_str;
10098
zend_string *str = zval_get_tmp_string(val, &tmp_str);
@@ -127,7 +125,7 @@ static int php_get_address_from_array(const HashTable *ht, const char *key,
127125
zend_string *str, *tmp_str;
128126

129127
if ((val = zend_hash_str_find(ht, key, strlen(key))) == NULL) {
130-
php_error_docref(NULL, E_WARNING, "No key \"%s\" passed in optval", key);
128+
zend_value_error("No key \"%s\" passed in optval", key);
131129
return FAILURE;
132130
}
133131
str = zval_get_tmp_string(val, &tmp_str);
@@ -282,8 +280,7 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock,
282280
case IP_MULTICAST_TTL:
283281
convert_to_long_ex(arg4);
284282
if (Z_LVAL_P(arg4) < 0L || Z_LVAL_P(arg4) > 255L) {
285-
php_error_docref(NULL, E_WARNING,
286-
"Expected a value between 0 and 255");
283+
zend_value_error("Expected a value between 0 and 255");
287284
return FAILURE;
288285
}
289286
ipv4_mcast_ttl_lback = (unsigned char) Z_LVAL_P(arg4);
@@ -347,8 +344,7 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
347344
case IPV6_MULTICAST_HOPS:
348345
convert_to_long_ex(arg4);
349346
if (Z_LVAL_P(arg4) < -1L || Z_LVAL_P(arg4) > 255L) {
350-
php_error_docref(NULL, E_WARNING,
351-
"Expected a value between -1 and 255");
347+
zend_value_error("Expected a value between -1 and 255");
352348
return FAILURE;
353349
}
354350
ov = (int) Z_LVAL_P(arg4);
@@ -496,8 +492,7 @@ static int _php_mcast_join_leave(
496492
}
497493
#endif
498494
else {
499-
php_error_docref(NULL, E_WARNING,
500-
"Option %s is inapplicable to this socket type",
495+
zend_value_error("Option %s is inapplicable to this socket type",
501496
join ? "MCAST_JOIN_GROUP" : "MCAST_LEAVE_GROUP");
502497
return -2;
503498
}

ext/sockets/sendrecvmsg.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ inline ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
6969
#define LONG_CHECK_VALID_INT(l) \
7070
do { \
7171
if ((l) < INT_MIN && (l) > INT_MAX) { \
72-
php_error_docref(NULL, E_WARNING, "The value " ZEND_LONG_FMT " does not fit inside " \
73-
"the boundaries of a native integer", (l)); \
72+
zend_value_error("The value " ZEND_LONG_FMT " does not fit inside the boundaries of a native integer", \
73+
(l)); \
7474
return; \
7575
} \
7676
} while (0)
@@ -290,23 +290,21 @@ PHP_FUNCTION(socket_cmsg_space)
290290
LONG_CHECK_VALID_INT(n);
291291

292292
if (n < 0) {
293-
php_error_docref(NULL, E_WARNING, "The third argument "
294-
"cannot be negative");
293+
zend_value_error("The third argument cannot be negative");
295294
return;
296295
}
297296

298297
entry = get_ancillary_reg_entry(level, type);
299298
if (entry == NULL) {
300-
php_error_docref(NULL, E_WARNING, "The pair level " ZEND_LONG_FMT "/type " ZEND_LONG_FMT " is "
301-
"not supported by PHP", level, type);
299+
zend_value_error("The pair level " ZEND_LONG_FMT "/type " ZEND_LONG_FMT " is not supported by PHP",
300+
level, type);
302301
return;
303302
}
304303

305304
if (entry->var_el_size > 0 && n > (zend_long)((ZEND_LONG_MAX - entry->size -
306305
CMSG_SPACE(0) - 15L) / entry->var_el_size)) {
307306
/* the -15 is to account for any padding CMSG_SPACE may add after the data */
308-
php_error_docref(NULL, E_WARNING, "The value for the "
309-
"third argument (" ZEND_LONG_FMT ") is too large", n);
307+
zend_value_error("The value for the third argument (" ZEND_LONG_FMT ") is too large", n);
310308
return;
311309
}
312310

0 commit comments

Comments
 (0)