Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: segfault in strftime



On 2010-02-26 15:17:12 +0000, Peter Stephenson wrote:
> I hope we don't need to handle the case sizeof(time_t) >
> sizeof(unsigned long). It's certainly not typical.

The problem would be more a signed time_t that cannot represent
ULONG_MAX: (time_t)ULONG_MAX would have an implementation-defined
behavior, e.g. process killed by a signal. And time_t is typically
defined as a long int!

Wouldn't it be better to test only errno != 0 ?

> 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') {

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author