From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lb2-smtp-cloud9.xs4all.net (lb2-smtp-cloud9.xs4all.net [194.109.24.26]) by sourceware.org (Postfix) with ESMTPS id 07B93383F878 for ; Wed, 4 Nov 2020 11:36:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 07B93383F878 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ubero.nl Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=udo.de.boer@ubero.nl Received: from cust-8971c19d ([IPv6:fc0c:c1a4:8534:9332:ccdf:8887:291d:b849]) by smtp-cloud9.xs4all.net with ESMTPA id aH5qkUYcA1R0xaH5rkHamr; Wed, 04 Nov 2020 12:36:47 +0100 Received: from localhost (localhost [127.0.0.1]) by central.ubero.nl (Postfix) with ESMTP id 3A9174B61D98 for ; Wed, 4 Nov 2020 12:36:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ubero.nl Received: from central.ubero.nl ([127.0.0.1]) by localhost (central.ubero.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rBe-mB_B3aYU for ; Wed, 4 Nov 2020 12:36:45 +0100 (CET) Received: from [10.135.0.18] (central.ubero.nl [10.135.0.18]) by central.ubero.nl (Postfix) with ESMTP id 27A594B61D02 for ; Wed, 4 Nov 2020 12:36:45 +0100 (CET) To: newlib@sourceware.org From: Udo de Boer Subject: Bug in UTC -> localtime conversion after 2038 Message-ID: <5d87b235-f246-1bab-f225-484c6fd93b4d@ubero.nl> Date: Wed, 4 Nov 2020 12:36:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CMAE-Envelope: MS4xfAdlA9UINxO5dNPDmAMECqMFLPTJrIyOskDIGDmfioApF9Wf6Mc3+8Sx0PcExMEAcNr6T509vTFEAJpi/aHXwLIhFVFC4mtVUE37DCqRl3AzDCQIldB2 hgbrrOI5SyuS78zbbdrCMZ/u43jqJBjwx6ZySp4x3M+yp5rdUT20XV2MbWlbq3MFlInoKJ+5zDlUjwfj+j7UkGylWcUJoDsJDkw= X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Nov 2020 11:36:52 -0000 Hi, UTC time to local timezone conversion did not work for years after 2038. Daylight saving in the timezone was not recognized. Tested on 32bit xtensa architecture with GCC 8.4 (esp32) and with 64bit time_t enabled. The struct tm is filled correct. So year, day etc are all filled with the correct values. But the tm.tm_isdst is 0 and no daylight saving is applied. It was caused by the following calculation in time/tzcalc_limits.c at line 68        /* store the change-over time in GMT form by adding offset */        tz->__tzrule[i].change = days * SECSPERDAY +        tz->__tzrule[i].s + tz->__tzrule[i].offset; Here tz->__tzrule[i].change is a time_t (64bit). For some reason the compiler does the calculation in 32 bit. All variables used in the calculation are 32bit. I solved this locally by changing the lines to.        /* store the change-over time in GMT form by adding offset */        tz->__tzrule[i].change = (time_t)days * SECSPERDAY +        tz->__tzrule[i].s + tz->__tzrule[i].offset; Adding the cast time_t should not cause a problem when time_t is still 32bit. I don't know if this is correct solution. I also only needed this function. So more bugs like this could be hidden away in the time code.