develooper Front page | perl.perl5.porters | Postings from June 2017

sprint "%c" with negative arg

Thread Next
From:
Dave Mitchell
Date:
June 5, 2017 11:24
Subject:
sprint "%c" with negative arg
Message ID:
20170605112411.GL3074@iabyn.com
In 5.10, we fixed chr()'s handling of a negative arg:

    $ p -we'$x = chr(-100); printf "[%x]\n", ord($x)'
    Invalid negative number (-100) in chr at -e line 1.
    [fffd]
    $

i.e. it gives a warning and returns UNICODE_REPLACEMENT.

However, its moral equivalent, sprintf "%c" handles it differently/badly:

    $ p -we'$x = sprintf("%c", -100); printf "[%x]\n", ord($x)'
    Use of code point 0xFFFFFFFFFFFFFF9C is deprecated; the permissible max is 0x7FFFFFFFFFFFFFFF. This will be fatal in Perl 5.28 at -e line 1.
    Use of code point 0xFFFFFFFFFFFFFF9C is deprecated; the permissible max is 0x7FFFFFFFFFFFFFFF. This will be fatal in Perl 5.28 in ord at -e line 1.
    [ffffffffffffff9c]
    $

I propose that sprintf %c is changed to behave like chr() for -Ve args.


-- 
It's not that I'm afraid to die, I just don't want to be there when it
happens.
    -- Woody Allen

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About