Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sprintf() allows '0' flag after vector flag #11999

Open
p5pRT opened this issue Mar 11, 2012 · 4 comments
Open

sprintf() allows '0' flag after vector flag #11999

p5pRT opened this issue Mar 11, 2012 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 11, 2012

Migrated from rt.perl.org#111678 (status was 'open')

Searchable as RT111678$

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2012

From glitchmr@myopera.com

Created by glitchmr@myopera.com

sprintf() allows to insert '0' flag after vector flag though documentation
says that vector flag is after normal flags.

  printf '%v08b', '​:)'
  # Result​:
  # => 00111010.00101001
  # Expected result​:
  # => 111010. 101001

It doesn't happen with other flags.

  printf '%v-8b', '​:)'
  # Result​:
  # => %v-8b

Perl Info

Flags:
     category=core
     severity=low

Site configuration information for perl 5.14.2:

Configured by sshd_server at Fri Oct  7 15:14:49 2011.

Summary of my perl5 (revision 5 version 14 subversion 2) configuration:

   Platform:
     osname=MSWin32, osvers=5.2, archname=MSWin32-x64-multi-thread
     uname=''
     config_args='undef'
     hint=recommended, useposix=true, d_sigaction=undef
     useithreads=define, usemultiplicity=define
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=undef, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='C:/mingw/bin/gcc.exe', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE  
-DNO_STRICT -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS  
-DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS  
-DUSE_PERLIO -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields',
     optimize='-O2',
     cppflags='-DWIN32'
     ccversion='', gccversion='4.6.1', gccosandvers=''
     intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
     ivtype='__int64', ivsize=8, nvtype='double', nvsize=8,  
Off_t='__int64', lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='C:\mingw\bin\g++.exe', ldflags ='-L"C:\Perl64\lib\CORE"'
     libpth=\lib
     libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32  
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm  
-lversion -lodbc32 -lodbccp32 -lcomctl32 -lbufferoverflowU -lmsvcrt
     perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32  
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm  
-lversion -lodbc32 -lodbccp32 -lcomctl32 -lbufferoverflowU -lmsvcrt
     libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl514.lib
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags='-mdll -L"C:\Perl64\lib\CORE"'

Locally applied patches:
     ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl 5.14.2:
     C:/Perl64/site/lib
     C:/Perl64/lib
     .


Environment for perl 5.14.2:
     HOME=C:\Users\Konrad
     LANG (unset)
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     PATH=C:\Program Files (x86)\ActiveState Komodo IDE  
7\;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\PHP\;C:\Program  
Files (x86)\ATI Stream\bin\x86_64;C:\Program Files (x86)\ATI  
Stream\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program  
Files (x86)\ATI  
Technologies\ATI.ACE\Core-Static;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Parrot-3.8.0\bin;c:\rakudo\bin;C:\Program  
Files  
(x86)\Zend\MySQL51\bin;C:\Users\Konrad\AppData\Roaming\npm;C:\Program  
Files (x86)\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Program Files  
(x86)\Git\bin;C:\Program Files (x86)\Heroku;C:\Program Files  
(x86)\git\bin;C:\Program Files  
(x86)\git\cmd;C:\Ruby193\bin;C:\Tcl\bin;C:\Program Files (x86)\ActiveState  
Komodo IDE 7\;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files  
(x86)\PHP\;C:\Program Files (x86)\ATI Stream\bin\x86_64;C:\Program Files  
(x86)\ATI  
Stream\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program  
Files (x86)\ATI  
Technologies\ATI.ACE\Core-Static;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Parrot-3.8.0\bin;c:\rakudo\bin;C:\Program  
Files  
(x86)\Zend\MySQL51\bin;C:\Users\Konrad\AppData\Roaming\npm;C:\Program  
Files (x86)\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Program Files  
(x86)\Git\bin;C:\Program Files (x86)\Heroku;C:\Program Files  
(x86)\git\bin;C:\Program Files  
(x86)\git\cmd;C:\mingw\bin;C:\KDE\bin;C:\Python27;C:\android-sdk-windows\platform-tools;C:\android-sdk-windows\tools;c:\Python27\Scripts;C:\Program  
Files\Java\jdk1.7.0_03\bin
     PERL_BADLANG (unset)
     PERL_JSON_BACKEND=JSON::XS
     PERL_YAML_BACKEND=YAML
     SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2012

From tchrist@perl.com

sprintf() allows to insert '0' flag after vector flag though documentation
says that vector flag is after normal flags.

printf '%v08b'\, '​:\)'
\# Result​:
\# => 00111010\.00101001
\# Expected result​:
\# =>   111010\.  101001

I use this all the time.

  % perl -e 'printf "U+%v04X\n", "abc"'
  U+0061.0062.0063

--tom

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2012

From @demerphq

On 12 March 2012 01​:52, Tom Christiansen <tchrist@​perl.com> wrote​:

sprintf() allows to insert '0' flag after vector flag though documentation
says that vector flag is after normal flags.

    printf '%v08b', '​:)'
    # Result​:
    # => 00111010.00101001
    # Expected result​:
    # =>   111010.  101001

I use this all the time.

   % perl -e 'printf "U+%v04X\n", "abc"'
   U+0061.0062.0063

I think this bug could be rewritten as "v flag in sprintf format
doesn't play well with other options and has hokey parse rules".

Play around with the format. "%v04X" and "%0v4X" both do the same
thing. It seems like you cant use negative formatting, nor the normal
* style length options. For instance id expect "%v0*X", 4 to work the
same as "%v04X", and id expected "%v-4X" to also work, but they don't.

cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants