* core: fix increment/decrement of options weechat.notify.*
* irc: add missing tags on multiline messages (issue #1987)
* irc: fix redirection of command `/list` when the reply doesn't start with message 321 (start of /list)
+ * xfer: fix conversion of string to IPv4 on 32-bit systems (issue #1999)
Tests::
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
xfer_network_convert_integer_to_ipv4 (const char *str_address)
{
char *error, result[128];
- long number;
+ long long number;
if (!str_address || !str_address[0])
return NULL;
- number = strtol (str_address, &error, 10);
- if (!error || error[0] || (number <= 0))
+ number = strtoll (str_address, &error, 10);
+ if (!error || error[0] || (number <= 0) || (number > UINT32_MAX))
return NULL;
snprintf (result, sizeof (result),
- "%ld.%ld.%ld.%ld",
+ "%lld.%lld.%lld.%lld",
(number >> 24) & 0xFF,
(number >> 16) & 0xFF,
(number >> 8) & 0xFF,
POINTERS_EQUAL(NULL, xfer_network_convert_integer_to_ipv4 ("0"));
POINTERS_EQUAL(NULL, xfer_network_convert_integer_to_ipv4 ("-1"));
+ /* too big: UINT32_MAX + 1 = 4294967296 */
+ POINTERS_EQUAL(NULL, xfer_network_convert_integer_to_ipv4 ("4294967296"));
+
WEE_TEST_STR("0.0.0.1", xfer_network_convert_integer_to_ipv4 ("1"));
WEE_TEST_STR("0.0.1.0", xfer_network_convert_integer_to_ipv4 ("256"));
WEE_TEST_STR("0.1.0.0", xfer_network_convert_integer_to_ipv4 ("65536"));