From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102945 invoked by alias); 20 May 2016 04:22:48 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 102928 invoked by uid 89); 20 May 2016 04:22:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=bg, BG, $B!G, $b!g X-HELO: mgwym02.jp.fujitsu.com Received: from mgwym02.jp.fujitsu.com (HELO mgwym02.jp.fujitsu.com) (211.128.242.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 20 May 2016 04:22:46 +0000 Received: from yt-mxoi2.gw.nic.fujitsu.com (unknown [192.168.229.69]) by mgwym02.jp.fujitsu.com with smtp id 2742_2a2f_7aaa1b94_5183_4130_b8ab_cb7cc0905ad9; Fri, 20 May 2016 13:22:37 +0900 Received: from dm.kawasaki.flab.fujitsu.co.jp (dm.kawasaki.flab.fujitsu.co.jp [10.25.192.105]) by yt-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 20190AC02F3 for ; Fri, 20 May 2016 13:22:37 +0900 (JST) Received: from localhost (hv-win7-64-144.flabad.flab.fujitsu.co.jp [10.25.198.94]) by dm.kawasaki.flab.fujitsu.co.jp (8.14.4/8.14.4) with ESMTP id u4K4Ma3b010046 for ; Fri, 20 May 2016 13:22:36 +0900 X-SecurityPolicyCheck: OK by SHieldMailChecker v2.2.3 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20140219-2 Date: Fri, 20 May 2016 04:22:00 -0000 Message-ID: From: KOBAYASHI Shinji To: cygwin@cygwin.com Subject: Invalid tm_zone from localtime() when TZ is not set In-Reply-To: <932D033F-9DA4-4901-9158-328AA929FEC8@etr-usa.com> References: <932D033F-9DA4-4901-9158-328AA929FEC8@etr-usa.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/24.5 (x86_64-unknown-cygwin) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-2022-JP X-TM-AS-MML: disable X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00216.txt.bz2 >>>>> Warren Young wrote: > How about you just give the line of code and explain what’s wrong with it? Then someone with checkin rights can reimplement your change from your prose description. Thank you for your suggestion. So I try to describe the problem: Current localtime() can return invalid tm_zone when used with non-English Windows and the TZ environment variable is unset. This leads to a failure of importing time module in Python 3: % (unset TZ; python3 -c "import time") Traceback (most recent call last): File "", line 1, in SystemError: initialization of time raised unreported exception Although most users set the TZ environment variable, tox (>= 2.0) drops most environment variables including TZ by default when invoking test environments. So the users of tox on non-English Windows may suffer from this problem. localtime() calls tzsetwall() when TZ is not set. In tzsetwall(), the StandardName and DaylightName member values retrieved by GetTimeZoneInformation() are checked with isupper() and copied to the char[] buffer used as the timezone name in tzparse(). However, the type of these member values are wchar_t and isupper() is defined only when isascii() is true. So it may happen that the char[] buffer contains invalid characters as a result of implicit cast from wchar_t to char. The return value of isupper() for non-ascii characters depends on other data, because an out of bounds access occurs for the small (128 + 256) table used in isupper(). I confirmed the above error on Japanese Windows with 64-bit Cygwin 2.5.0-1 and 2.5.1-1, but had no problem with 64-bit Cygwin 2.4.1-1 nor with 32-bit Cygwins. So, I propose to call isascii() to assure the wchar_t fits in the range of ASCII before calling isupper(). I have considered some other methods: 1. Using iswupper() instead of isupper(). - Although this method is effective for Japanese environments, it is not assured that the character iswupper() returns true fits in the range of ASCII. 2. Add (char) cast to the argument of isupper(). - This method assures that the copied characters are uppercase only. However, it may be different from original characters due to casting. So I think that adding isascii() calls is better than these methods. Regards, KOBAYASHI Shinji. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple