Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect pointer arithmetics because of LARGEADDRESSAWARE

I would like to switch my application to LARGEADDRESSAWARE. One of issues to watch for is pointer arithmetic, as pointer difference can no longer be represented as signed 32b.

Is there some way how to find automatically all instances of pointer subtraction in a large C++ project?

If not, is there some "least effort" manual or semi-automatic method how to achieve this?

like image 265
Suma Avatar asked Jun 16 '10 09:06

Suma


1 Answers

PC-Lint can find this kind of problem.

Look at http://gimpel-online.com/MsgRef.html, error code 947:

Subtract operator applied to pointers -- An expression of the form p - q was found where both p and q are pointers. This is of special importance in cases where the maximum pointer can overflow the type that holds pointer differences. For example, suppose that the maximum pointer is 3 Gigabytes -1, and that pointer differences are represented by a long, where the maximum long is 2 Gigabytes -1. Note that both of these quantities fit within a 32 bit word. Then subtracting a small pointer from a very large pointer will produce an apparent negative value in the long representing the pointer difference. Conversely, subtracting a very large pointer from a small pointer can produce a positive quantity.

like image 190
Patrick Avatar answered Sep 17 '22 12:09

Patrick