From patchwork Thu Jan 26 13:50:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 63737 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76CA03858416 for ; Thu, 26 Jan 2023 13:51:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76CA03858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674741077; bh=zYJ5+MyWStvmyM/5p+h90cKd7oW2LqhWIT9YYXrLkNw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=iR39+4aaQiExonnl0nzxNQMHkz1SJloYdLLGgHmuTzpallBou6DC+EiGyOOuGEyBS bj2cTN+RsXAuncxxZtbdMxZvw+p36r7GltgwCgqkBU973eVYkYtDQS3cdKLf3Kw8/5 a3d7bizy3uIX06qY8ihaImUraCamGgL6hAP5uxAc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 35E1F3858D28 for ; Thu, 26 Jan 2023 13:50:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35E1F3858D28 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-461-Ev4bS4azOr-8HDpK0IXOQA-1; Thu, 26 Jan 2023 08:50:47 -0500 X-MC-Unique: Ev4bS4azOr-8HDpK0IXOQA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 550EE3C31DE9; Thu, 26 Jan 2023 13:50:47 +0000 (UTC) Received: from localhost (unknown [10.33.36.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 199442166B26; Thu, 26 Jan 2023 13:50:46 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add workaround for old tzdata.zi files Date: Thu, 26 Jan 2023 13:50:46 +0000 Message-Id: <20230126135046.1441243-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux (Fedora 36 and RHEL 6.10). Pushed to trunk. -- >8 -- The tzdata.zi file in the RHEL 6 tzdata-2018e-3.el6 package (with version "unknown") does not conform to the current rules described in the zic(8) man page. Specifically, a Rule name must not start with the character '+' in the current rules, but the older tzdata.zi file used "+" as the name of rules for the "Europe/Sofia" zone. Add a special case to the logic that detects whether a RULES field refers to a named rule or is an offset from standard time. For a string matching exactly "+" treat it as a named Rule, but for any other string starting with '+' treat it as an offset. libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (operator>>(istream&, ZoneInfo&)): Allow rules named "+" for compatibility with older tzdata.zi files. --- libstdc++-v3/src/c++20/tzdb.cc | 49 +++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index c945f002ad7..c956e861891 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -1967,6 +1967,22 @@ namespace std::chrono return in; } + // Test whether the RULES field of a Zone line is a valid Rule name. + inline bool + is_rule_name(string_view rules) noexcept + { + // The NAME field of a Rule line must start with a character that is + // neither an ASCII digit nor '-' nor '+'. + if (('0' <= rules[0] && rules[0] <= '9') || rules[0] == '-') + return false; + // However, some older tzdata.zi files (e.g. in tzdata-2018e-3.el6 RPM) + // used "+" as a Rule name, so we need to handle that special case. + if (rules[0] == '+') + return rules.size() == 1; // "+" is a rule name, "+1" is not. + // Everything else is the name of a Rule. + return true; + } + istream& operator>>(istream& in, ZoneInfo& inf) { // STDOFF RULES FORMAT [UNTIL] @@ -1976,25 +1992,28 @@ namespace std::chrono in >> off >> quoted{rules} >> fmt; inf.m_offset = off.time; - if (rules == "-") + if (is_rule_name(rules)) { - // Standard time always applies, no DST. - inf.set_abbrev(fmt); - } - else if (string_view("0123456789-+").find(rules[0]) != string_view::npos) - { - // rules specifies the difference from standard time. - at_time rules_time; - istringstream in2(std::move(rules)); - in2 >> rules_time; - inf.m_save = duration_cast(rules_time.time); - select_std_or_dst_abbrev(fmt, inf.m_save); - inf.set_abbrev(fmt); + // `rules` refers to a named Rule which describes transitions. + inf.set_rules_and_format(rules, fmt); } else { - // rules refers to a named Rule which describes transitions. - inf.set_rules_and_format(rules, fmt); + if (rules == "-") + { + // Standard time always applies, no DST. + } + else + { + // `rules` specifies the difference from standard time, + // e.g., "-2:30" + at_time rules_time; + istringstream in2(std::move(rules)); + in2 >> rules_time; + inf.m_save = duration_cast(rules_time.time); + select_std_or_dst_abbrev(fmt, inf.m_save); + } + inf.set_abbrev(fmt); } // YEAR [MONTH [DAY [TIME]]]