Re: bug with built-in printf

2006-12-06 Thread Eric Blake
Chet Ramey  case.edu> writes:

> > Using printf with a large integer results in incorrect conversion to
> > hexadecimal.
> > 
> > Repeat-By:
> > 
> > printf "%08X" 2604292517
> > 
> > On this version results in the incorrect string "-64C5A65B".
> 
> Thanks.  I fixed it.

In the interest of open source, this is how I reproduced a fix for cygwin:

--- bash-3.2-orig/lib/sh/snprintf.c 2006-12-06 07:17:51.724375000 -0700
+++ bash-3.2/lib/sh/snprintf.c  2006-12-06 07:09:03.0 -0700
@@ -7,7 +7,7 @@
Unix snprintf implementation.
derived from inetutils/libinetutils/snprintf.c Version 1.1
 
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2006 Free Software Foundation, Inc.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General License as published by
@@ -668,7 +668,8 @@
 p->flags &= ~PF_ZEROPAD;
 
   sd = d;  /* signed for ' ' padding in base 10 */
-  flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0;
+  flags = (*p->pf == 'u' || *p->pf == 'U' || *p->pf == 'x' || *p->pf == 'X'
+  || *p->pf == 'o') ? FL_UNSIGNED : 0;
   if (*p->pf == 'X')
 flags |= FL_HEXUPPER;
 
@@ -738,7 +739,8 @@
 p->flags &= ~PF_ZEROPAD;
 
   sd = d;  /* signed for ' ' padding in base 10 */
-  flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0;
+  flags = (*p->pf == 'u' || *p->pf == 'U' || *p->pf == 'x' || *p->pf == 'X'
+  || *p->pf == 'o') ? FL_UNSIGNED : 0;
   if (*p->pf == 'X')
 flags |= FL_HEXUPPER;
 
-- 
Eric Blake




___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: mkfifo and tee within a function

2006-12-06 Thread Eric Blake
Chet Ramey  case.edu> writes:

> > $>cmd_print () { mkfifo zout ; (tee zout &); cat zout ; rm zout; }
> > $>printf 'hello\n' | cmd_print
> 
> When job control is not active, Posix requires that a command run in the
> background with `&' behave as if its standard input were /dev/null in the
> absence of any explicit redirection.  Bash counts a pipe directly into
> such a command as one such redirection, but not the pipe into the shell
> function.

Actually, POSIX states this:

"The standard input for an asynchronous list, before any explicit redirections 
are performed, shall be considered to be assigned to a file that has the same 
properties as /dev/null. If it is an interactive shell, this need not happen. 
In all cases, explicit redirection of standard input shall override this 
activity."

In other words, the presence or absence of job control is not the best criteria 
for whether to do the /dev/null redirection.  The initial /dev/null redirection 
MUST occur in non-interactive shells, even if job control is active.  However, 
for interactive shells, it is still acceptable to use the presence of job 
control as a hook for deciding whether to perform the redirection.

-- 
Eric Blake





___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash