php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14382 sprintf function doesn't print correct results
Submitted: 2001-12-07 13:47 UTC Modified: 2002-01-14 02:08 UTC
From: jiri dot kaderavek at webstep dot net Assigned:
Status: Closed Package: Variables related
PHP Version: 4.1.0 OS: Debian GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jiri dot kaderavek at webstep dot net
New email:
PHP Version: OS:

 

 [2001-12-07 13:47 UTC] jiri dot kaderavek at webstep dot net
Sometimes (1-10 times a day) appears a fatal bug
in my php code. Sometime this sprintf expression returns me string like '0.05-0%':

<?echo $rs["pol_sazbadph"]."-".sprintf("%1.0f",$rs["pol_sazbadph"] * 100)."%"?>

This bug appears to me on two different servers:

1) Athlon based 2.4.12-k6 kernel - Apache/1.3.22 - php 4.1.0 RC3

?'./configure' '--prefix=/usr' '--with-apxs=/usr/bin/apxs' '--with-config-file-path=/ etc/php4/apache' '--with-ibm-db2=/home/db2inst1/sqllib' 

2) Pentium II based - 2.2.19pre17 kernel - Apache/1.3.9 - 
php 4.0.3pl1

'./configure' '--prefix=/usr' '--with-apxs=/usr/bin/apxs' '--with-regex=system' '--with- config-file-path=/etc/php4/apache' '--with-db2' '--with-zlib' '--without-pgsql' '-- disable-static' '--with-layout=GNU' '--with-zlib-dir=/usr' '--with-mysql=shared,/usr' '-- with-ibm-db2=/home/db2inst1/sqllib'

The bug appears after we have compiled php against db2 libraries. I've found another bug in sprintf with the same frequency of appearance in bugs database. There is something bad in sprintf in some cases, but what?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-11 08:38 UTC] jiri dot kaderavek at webstep dot net
This is the problem of syntax checking and locale settings.
This script print a warning:

setlocale(LC_ALL, "en_US");  // US have a decimal pointer
$X = 1,22;                   // !!! bad syntax 

This script doesn't print a warning:

setlocale(LC_ALL, "cs_CZ"); // CZ have a decimal comma
$X = 1.22;                  // !!! also bad syntax

The error caused by incorrect parsing of a float number is propagated into the next script lines and cause a false alerts in a many situations. When the variable is parsed as a string

 [2001-12-11 08:41 UTC] jiri dot kaderavek at webstep dot net

 [2001-12-24 10:08 UTC] sander@php.net
Can you provide a _self-contained_ sample script which reproduces the problem.

BTW: $X = 1.22; is not bad syntax. It's just the way you represent decimal values in PHP, no matter what the current locale is.
 [2002-01-14 02:08 UTC] lobbin@php.net
No feedback, closing.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Sep 26 09:01:24 2020 UTC