classification
Title: Arithmetic operations with NULL
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: jcea, mark.dickinson, serhiy.storchaka, vstinner
Priority: normal Keywords: 3.3regression, patch

Created on 2012-10-12 22:45 by serhiy.storchaka, last changed 2013-01-15 11:55 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
null_align.patch serhiy.storchaka, 2012-10-12 22:45 review
Messages (4)
msg172791 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-12 22:45
In the function STRINGLIB(fastsearch_memchr_1char) in the file Objects/stringlib/fastsearch.h NULL returned by memchr/memrchr casted to intptr_t, then some arithmetic operations performed on this integer, and result casted back to pointer. I think it is unsafe to do with NULL. The code is easy to rewrite in order to avoid such a questionable operations.
msg172792 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-10-12 23:47
> I think it is unsafe to do with NULL.

Could you please elaborate?
msg172800 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-13 08:16
The Standard is not guarantee that result of converting null pointer to integer is zero or even it is a even number. I remember the ancient C implementation, where it was not so (but Python is not supports these platform).

Of course, such a method of obtaining aligned pointers is one great trick. I'm not sure whether to worry about that.
msg180011 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-15 11:55
Oh, I forgot to mention the issue number in commit messages. There are changeset ad9b5c69b8b6 (for 3.3) and changeset 1f66fc397c8d (for default).
History
Date User Action Args
2013-01-15 11:55:27serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg180011

stage: patch review -> resolved
2012-12-27 20:52:37serhiy.storchakasetassignee: serhiy.storchaka
2012-11-26 18:15:29jceasetnosy: + jcea
2012-10-25 16:34:40ezio.melottisettype: behavior
2012-10-24 09:28:31serhiy.storchakasetstage: patch review
2012-10-13 08:16:00serhiy.storchakasetnosy: + mark.dickinson
messages: + msg172800
2012-10-12 23:47:29vstinnersetnosy: + vstinner
messages: + msg172792
2012-10-12 22:45:08serhiy.storchakacreate