Commit 51a2ce5
committed
zend_atoi/zend_atol cleanup
zend_ato[il]() don't *just* do number parsing.
They also check for a 'K', 'M', or 'G' at the end of the string,
and multiply the parsed value out accordingly.
Unfortunately, they ignore any other non-numerics between the
numeric component and the last character in the string.
This means that numbers such as the following are both valid
and non-intuitive in their final output.
* "123KMG" is interpreted as "123G" -> 132070244352
* "123G " is interpreted as "123 " -> 123
* "123GB" is interpreted as "123B" -> 123
* "123 I like tacos." is also interpreted as "123." -> 123
This diff primarily adds warnings for these cases when the output
would be a potentially unexpected, and unhelpful value.
Additionally, several places in php-src use these functions
despite not actually wanting their KMG behavior such as
session.upload_progress.freq which will happily parse "1 banana"
as a valid value.
For these settings, I've switched them to ZEND_STRTOL which preserves
their existing /intended/ behavior.
* It won't respect KMG suffixes, but they never really wanted that logic anyway.
* It will ignore non-numeric suffixes so as to not introduce new failures.
We should probably reexamine that second bullet point separately.
Lastly, with these changes, zend_atoi() is no longer used in php-src,
but I left it as a valid API for 3rd party extensions.
Note that I did make it a proxy to zend_atol() since deferring the
truncation till the end is effectively the same as truncation during
multiplication, but this avoid code duplication.
I think we should consider removing zend_atoi() entirely (perhaps in 8.0?)
and rename zend_atol() to something reflecting it's KMG specific behavior.1 parent fc42ac2 commit 51a2ce5
File tree
6 files changed
+64
-48
lines changed- Zend
- ext
- session
- standard
- zlib
6 files changed
+64
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
831 | | - | |
| 831 | + | |
832 | 832 | | |
833 | 833 | | |
834 | 834 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2705 | 2705 | | |
2706 | 2706 | | |
2707 | 2707 | | |
2708 | | - | |
| 2708 | + | |
2709 | 2709 | | |
2710 | 2710 | | |
2711 | 2711 | | |
| |||
2717 | 2717 | | |
2718 | 2718 | | |
2719 | 2719 | | |
2720 | | - | |
| 2720 | + | |
2721 | 2721 | | |
2722 | 2722 | | |
2723 | 2723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
81 | | - | |
| 83 | + | |
82 | 84 | | |
83 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
84 | 89 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
106 | 100 | | |
107 | 101 | | |
108 | 102 | | |
109 | 103 | | |
110 | 104 | | |
111 | 105 | | |
| 106 | + | |
112 | 107 | | |
113 | 108 | | |
114 | 109 | | |
115 | 110 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
132 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
133 | 149 | | |
134 | 150 | | |
135 | 151 | | |
| |||
3007 | 3023 | | |
3008 | 3024 | | |
3009 | 3025 | | |
3010 | | - | |
| 3026 | + | |
3011 | 3027 | | |
3012 | 3028 | | |
3013 | 3029 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
768 | 768 | | |
769 | 769 | | |
770 | 770 | | |
771 | | - | |
772 | | - | |
| 771 | + | |
| 772 | + | |
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5994 | 5994 | | |
5995 | 5995 | | |
5996 | 5996 | | |
5997 | | - | |
| 5997 | + | |
5998 | 5998 | | |
5999 | 5999 | | |
6000 | 6000 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1436 | 1436 | | |
1437 | 1437 | | |
1438 | 1438 | | |
1439 | | - | |
| 1439 | + | |
1440 | 1440 | | |
1441 | 1441 | | |
1442 | 1442 | | |
| |||
0 commit comments