From 392eef7900fdedda28f9c3aff5b0434f963a7f86 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 18 Jul 2018 00:19:24 +0000 Subject: [PATCH] Correct the max hostname length constant. 256 bytes including NUL byte is confusing and makes for really annoying bindings to other languages that don't account for NUL bytes in their string length. We pass C strings, not byte arrays, for hostnames, so 255 makes more sense here. --- toxcore/tox.api.h | 6 +++--- toxcore/tox.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 632d79c5..c77ac685 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h @@ -318,12 +318,12 @@ const MAX_FILENAME_LENGTH = 255; /** * Maximum length of a hostname, e.g. proxy or bootstrap node names. * - * This length includes the NUL byte. Hostnames are NUL-terminated C strings, so - * they are 255 characters plus one NUL byte. + * This length does not include the NUL byte. Hostnames are NUL-terminated C + * strings, so they are 255 characters plus one NUL byte. * * @deprecated The macro will be removed in 0.3.0. Use the function instead. */ -const MAX_HOSTNAME_LENGTH = 256; +const MAX_HOSTNAME_LENGTH = 255; /******************************************************************************* diff --git a/toxcore/tox.h b/toxcore/tox.h index 6a4df16d..40d37b0b 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -345,12 +345,12 @@ uint32_t tox_max_filename_length(void); /** * Maximum length of a hostname, e.g. proxy or bootstrap node names. * - * This length includes the NUL byte. Hostnames are NUL-terminated C strings, so - * they are 255 characters plus one NUL byte. + * This length does not include the NUL byte. Hostnames are NUL-terminated C + * strings, so they are 255 characters plus one NUL byte. * * @deprecated The macro will be removed in 0.3.0. Use the function instead. */ -#define TOX_MAX_HOSTNAME_LENGTH 256 +#define TOX_MAX_HOSTNAME_LENGTH 255 uint32_t tox_max_hostname_length(void);