# [PATCH] Small typo in zend_u_strtol

- Thread: https://externals.io/message/25820
- Original archive: https://news-web.php.net/php.internals/25820
- Started by Matt W on 2006-09-25T14:26:52+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #25820 — Matt W — 2006-09-25T14:26:52+00:00

URL: https://externals.io/message/25820#25820

Hi,

Noticed this a couple months ago and never sent this simple thing. :-)
ERANGE is being triggered too soon because of the wrong variable, which
causes the following (in Unicode mode, of course) on 32-bit:

(int) '2147483640' // int(2147483647)
'2147483640' + 0) // float(2147483640)

Instead of the expected int(2147483640) in both cases.


Matt

---

## #25945 — Matt W — 2006-10-05T08:50:28+00:00

URL: https://externals.io/message/25820#25945 · In reply to: #25820

Hi,

Was this missed?  I'm sure you want to fix it. :-)  Maybe should've put
"bug" instead of "typo" in the subject...

Just also sending to you Andrei since it's Unicode related.

Patch was an attachment: http://news.php.net/php.internals/25820


----- Original Message -----
From: "Matt W"
Sent: Monday, September 25, 2006


> Hi,
>
> Noticed this a couple months ago and never sent this simple thing. :-)
> ERANGE is being triggered too soon because of the wrong variable, which
> causes the following (in Unicode mode, of course) on 32-bit:
>
> (int) '2147483640' // int(2147483647)
> '2147483640' + 0 // float(2147483640)
>
> Instead of the expected int(2147483640) in both cases.
>
>
> Matt

---

## #25952 — Andrei Zmievski — 2006-10-05T16:28:01+00:00

URL: https://externals.io/message/25820#25952 · In reply to: #25945

Are you sure this is correct? I copied the source from BSD strtol  
implementation.

http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdlib/strtol.c? 
rev=1.19&content-type=text/x-cvsweb-markup

-Andrei



> Hi,
>
> Was this missed?  I'm sure you want to fix it. :-)  Maybe should've put
> "bug" instead of "typo" in the subject...
>
> Just also sending to you Andrei since it's Unicode related.
>
> Patch was an attachment: http://news.php.net/php.internals/25820
>
>
> ----- Original Message -----
> From: "Matt W"
> Sent: Monday, September 25, 2006
>
>
> > […]

---

## #25956 — Matt W — 2006-10-05T23:46:08+00:00

URL: https://externals.io/message/25820#25956 · In reply to: #25952

Hi Andrei,

----- Original Message -----
From: "Andrei Zmievski"
Sent: Thursday, October 05, 2006


> Are you sure this is correct? I copied the source from BSD strtol
> implementation.
>
> http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdlib/strtol.c?
> rev=1.19&content-type=text/x-cvsweb-markup

Well, copied but modified for Unicode use... like half the for loop is
changed.  In BSD's case, the value of '0', etc. is subtracted from "c"
variable, so it then has the actual numeric value of the digit.  But PHP's
puts the actual numeric value in "val" from u_digit(). "c" is still too high
by '0' 's value (48?).  Finally, their "acc += c" was changed to "acc +=
val" for that reason.  If PHP's had kept "c" *there*, the problem would've
been discovered fast. :-)

Do you see the problem in the examples I gave?  Numbers between 2147483640
and 2147483647 incorrectly set ERANGE, along with similar negative values.

> -Andrei

Matt

> 
>
> > […]
