Skip to content

Commit 22e8b20

Browse files
authored
Merge pull request #4792 from Neradoc/nera-fix-IPv4Address
Fix ipaddress.IPv4Address from returning invalid values
2 parents 9a7a2bb + 9fa7fb7 commit 22e8b20

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

locale/circuitpython.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ msgid "Only one color can be transparent at a time"
16941694
msgstr ""
16951695

16961696
#: shared-bindings/ipaddress/__init__.c
1697-
msgid "Only raw int supported for ip"
1697+
msgid "Only raw int or string supported for ip"
16981698
msgstr ""
16991699

17001700
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c

shared-bindings/ipaddress/IPv4Address.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ STATIC mp_obj_t ipaddress_ipv4address_make_new(const mp_obj_type_t *type, size_t
6060
uint8_t *buf = NULL;
6161
if (mp_obj_get_int_maybe(address, (mp_int_t *)&value)) {
6262
// We're done.
63-
buf = (uint8_t *)value;
63+
buf = (uint8_t *)&value;
6464
} else if (mp_obj_is_str(address)) {
6565
GET_STR_DATA_LEN(address, str_data, str_len);
6666
if (!ipaddress_parse_ipv4address((const char *)str_data, str_len, &value)) {
6767
mp_raise_ValueError(translate("Not a valid IP string"));
6868
}
69+
buf = (uint8_t *)&value;
6970
} else {
7071
mp_buffer_info_t buf_info;
7172
if (mp_get_buffer(address, &buf_info, MP_BUFFER_READ)) {

shared-bindings/ipaddress/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool ipaddress_parse_ipv4address(const char *str_data, size_t str_len, uint32_t
7676
return true;
7777
}
7878

79-
//| def ip_address(obj: Union[int]) -> IPv4Address:
79+
//| def ip_address(obj: Union[int, str]) -> IPv4Address:
8080
//| """Return a corresponding IP address object or raise ValueError if not possible."""
8181
//| ...
8282
//|
@@ -91,7 +91,7 @@ STATIC mp_obj_t ipaddress_ip_address(mp_obj_t ip_in) {
9191
mp_raise_ValueError(translate("Not a valid IP string"));
9292
}
9393
} else {
94-
mp_raise_ValueError(translate("Only raw int supported for ip"));
94+
mp_raise_ValueError(translate("Only raw int or string supported for ip"));
9595
}
9696

9797
return common_hal_ipaddress_new_ipv4address(value);

0 commit comments

Comments
 (0)