[PATCH] - fix for 64 bit issues with OnUpdateInt
| From: | Dave Hill | Date: | Thu, 27 Feb 2003 19:52:28 +0000 |
| Subject: | [PATCH] - fix for 64 bit issues with OnUpdateInt | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-94642@lists.php.net to get a copy of this message | ||
Proposed Patch to address 64 bit issues in PHP v4.3.1
Diff -u against php4-STABLE-200302241430
Also needed in 4.5.x and 5.x
Addresses bugs 20994, 21002, 21822, 20268
Platforms affected, Tru64, Solaris 9, HP-UX, NetBSD/Alpha and
any other 64 bit platform I forgot to mention....
A little education first....
on some platforms, sizeof(int) != sizeof(long)
This is particularly true on 64 bit platforms.
Mixed int* and long* in these cases can be deadly, and
can cause hard to find problems. This is because if
the machine writes to a long* that is really pointing at
an int, then "extra" data gets written past the end of the
int corrupting whatever is after that int.
Also on 64 bit platforms, only a long is going to be big enough
to hold a pointer, so assigning a pointer value to an int, and then
assigning it back will result in truncation of data.
Lastly, sizeof(size_t) == sizeof(long) which means if you plan to mix
things, don't mix size_t and int.
The particular problem that sparked this patch is a particular problem
with OnUpdateInt called from zlib, as this function assumes a &long is
passed in,
despite the name. In the source code - this function was passed a long
in about 70% of the cases, an int in rest. What was passed was not
always consitant in a particular source module.
I chose to address this problem by creating OnUpdateLong (in addition to
to existing OnUpdateInt) and sweep though the code changing the call
where needed to match the stucture item. An equally valid fix would be
to change all of those longs to ints.
After performing that sweep, I found there was a small number of other
errors of the int/long type that my compiler found that I corrected and
are included here. There might be more mix and match problems, I only
addressed the ones in the modules I have enabled.
Files affected:
Zend/zend_ini.c
Zend/zend_ini.h
ext/fbsql/php_fbsql.c
ext/hyperwave/hw.c
ext/ingres_ii/ii.c
ext/interbase/interbase.c
ext/ldap/ldap.c
ext/mbstring/mbstring.c
ext/mssql/php_mssql.c
ext/mysql/php_mysql.c
ext/odbc/php_odbc.c
ext/pgsql/pgsql.c
ext/session/session.c
ext/standard/assert.c
ext/standard/file.c
ext/standard/info.c
ext/standard/url_scanner_ex.c
ext/sybase_ct/php_sybase_ct.c
main/main.c
sapi/apache/php_apache.c