X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; q=dns; s=default; b=Es n6pq5XN4NGq+uXlItUUGjXZe8+qd0JhIe1etrkRoLu4pS9RIkAl4l7GdWqBC+ekk HXN+QkG21ts6hcRPgWl3FIbliWQxaUt5ES9L19Jy+BfIsTQfpye2W23QKuBJKZve NA3iumJNBW+TT9QQgA6y70hUsEsm01ik9CxpnhYDE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; s=default; bh=g6Lus/lN MhxUhlm4Fwhv1trptKc=; b=quT96MoCRqgUMGGFpFyH+v/yuPK78Ma7LrXUeJ4r uIe+sr41K/oiOzj3uStoniWD42pkIgshojNhVfJ1SJCcquWYeJxYPGZh40xb3ZrH nEpDIGfVKBz6hoEzAa0AKrQfRdjlg6viPiKf1aL8NyiGfBT8Nggni/0aZzWwMaqt k6E= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Tao, tao, H*i:sk:o8x8tz5, H*f:sk:o8x8tz5 X-HELO: mail-wm0-f52.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to; bh=y5m0FzgiXA1cIRSTw6/NUxYSC1YwylqTnePTRyDpI/o=; b=BToMGOLCZNHWR8HuntClWCQs0xMse1LCf3zfBM4ypKE8Kalqoh6QefWuSo/QuV/4cH i4AcRUAQ9Q1njtvElkH26biOmEwjY+bqMNtFQGsTNB8FjUVWXiR+dTXcMZCsh/fvRJr8 1ZB+6tnnrC/0tbuG4OyIdWdX7BJD+2Ir1+kMs8WqqAeni1MBj7VmZp+UIyXEH/gsoGFz wPJ01PedW5DaIvLKx55CooHY1xunXnbuzZH0LkBlJcOtb32OtoT1S0r6/vY7DhnwFQgs O/oEckH69p8LAJMbcg1Ki0FrxoEb/4bbxVVy0qXsyDqhGZezjhkxL1qZaU7ThxUGfoQT jwEQ== X-Gm-Message-State: AOPr4FWpVZYwOdHdmgRGmFcHGFAp17b9Z1aSznTUHW6ad7d+mCVd6NxOceQWnNGNzqeRWJUJ0xmOBWLtKmI3BQ== MIME-Version: 1.0 X-Received: by 10.194.64.35 with SMTP id l3mr1504442wjs.180.1463728166867; Fri, 20 May 2016 00:09:26 -0700 (PDT) In-Reply-To: References: <932D033F-9DA4-4901-9158-328AA929FEC8 AT etr-usa DOT com> Date: Fri, 20 May 2016 09:09:26 +0200 Message-ID: Subject: Re: Invalid tm_zone from localtime() when TZ is not set From: Csaba Raduly To: cygwin list Content-Type: text/plain; charset=UTF-8 On Fri, May 20, 2016 at 6:22 AM, KOBAYASHI Shinji wrote: (snip) > > 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. If the type of those members is WCHAR[] then using isascii() / isupper() on them is just plain wrong. The correct function to use would be iswupper(). The line if (isupper(*src)) *dst++ = *src; (where src is wchar_t* and dst is char*) assumes that the upper 8 bits of *src are zero (or *src is -1). If not, the behavior is at best implementation-defined (maybe even undefined). > 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. It is highly likely that if the argument of iswupper() does not fit into ASCII then its result won't fit either. > 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. > -- GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++ The Tao of math: The numbers you can count are not the real numbers. Life is complex, with real and imaginary parts. "Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds "People disagree with me. I just ignore them." -- Linus Torvalds -- 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