From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 633 invoked by alias); 26 Feb 2010 15:18:58 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 14900 Received: (qmail 26079 invoked from network); 26 Feb 2010 15:18:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Fri, 26 Feb 2010 15:17:12 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: segfault in strftime Message-ID: <20100226151712.05fbe555@news01> In-Reply-To: <20100226150748.GE13766@prunille.vinc17.org> References: <20100226125256.GC13766@prunille.vinc17.org> <20100226150748.GE13766@prunille.vinc17.org> Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 26 Feb 2010 15:17:12.0620 (UTC) FILETIME=[C58F66C0:01CAB6F6] X-Scanned-By: MailControl A-09-22-10 (www.mailcontrol.com) on 10.68.0.115 On Fri, 26 Feb 2010 16:07:49 +0100 Vincent Lefevre wrote: > > $ strftime "%a %d.%m.%Y %H:%M:%S" -1 > > strftime: -1: success > > Concerning this one: > > secs = (time_t)strtoul(argv[1], &endptr, 10); > if (secs == (time_t)ULONG_MAX) { > zwarnnam(nam, "%s: %e", argv[1], errno); > return 1; > } else if (*endptr != '\0') { > zwarnnam(nam, "%s: invalid decimal number", argv[1]); > return 1; > } > > ULONG_MAX is not necessarily an error! You need to check errno. I hope we don't need to handle the case sizeof(time_t) > sizeof(unsigned long). It's certainly not typical. Index: Src/Modules/datetime.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/datetime.c,v retrieving revision 1.19 diff -p -u -r1.19 datetime.c --- Src/Modules/datetime.c 26 Feb 2010 14:25:05 -0000 1.19 +++ Src/Modules/datetime.c 26 Feb 2010 15:15:12 -0000 @@ -111,8 +111,9 @@ bin_strftime(char *nam, char **argv, Opt if (OPT_ISSET(ops, 'r')) return reverse_strftime(nam, argv, scalar, OPT_ISSET(ops, 'q')); + errno = 0; secs = (time_t)strtoul(argv[1], &endptr, 10); - if (secs == (time_t)ULONG_MAX) { + if (secs == (time_t)ULONG_MAX && errno != 0) { zwarnnam(nam, "%s: %e", argv[1], errno); return 1; } else if (*endptr != '\0') { -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom