@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -555,15 +555,21 @@ if (portString.unsignedLongLongValue > 65535) @throw [OFInvalidFormatException exception]; _port = [[OFNumber alloc] initWithUnsignedShort: portString.unsignedLongLongValue]; - } else + } else { _URLEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String]; - if (!isIPv6Host) + if (_URLEncodedHost.length == 0) { + [_URLEncodedHost release]; + _URLEncodedHost = nil; + } + } + + if (_URLEncodedHost != nil && !isIPv6Host) OFURLVerifyIsEscaped(_URLEncodedHost, [OFCharacterSet URLHostAllowedCharacterSet]); if ((UTF8String = tmp) != NULL) { if ((tmp = strchr(UTF8String, '#')) != NULL) { @@ -586,12 +592,29 @@ OFURLVerifyIsEscaped(_URLEncodedQuery, [OFCharacterSet URLQueryAllowedCharacterSet]); } + /* + * Some versions of GCC issue a false-positive warning + * (turned error) about a string overflow. This is a + * false positive because UTF8String is set to tmp + * above and tmp is either NULL or points *after* the + * slash for the path. So all we do here is go back to + * that slash and restore it. + */ +#if OF_GCC_VERSION >= 402 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpragmas" +# pragma GCC diagnostic ignored "-Wunknown-warning-option" +# pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif UTF8String--; *UTF8String = '/'; +#if OF_GCC_VERSION >= 402 +# pragma GCC diagnostic pop +#endif _URLEncodedPath = [[OFString alloc] initWithUTF8String: UTF8String]; OFURLVerifyIsEscaped(_URLEncodedPath,