Question about splitting the destination of a NULL pointer in the address space of a process

I read <Windows via C / C ++ 5th edition> and the following is a quote:

Each virtual address space of the process is divided into sections. On x86 32-bit Windows, partition 0x00000000 - The 0x0000FFFF (inclusive) destination section of the NULL pointer is invoked. This section is intended to help programmers catch a NULL pointer job. If the stream in your aprocess is trying to read or write to the memory address in this partition, access to the cello is raised.

I am wondering why we should use the address space range instead of just the value 0 to catch the assignment of a NULL pointer? AFAIK, NULL is 0. So, what about this design? Is there anything else in this range that the user should not touch? Or is NULL not necessarily 0?

Many thanks.

+3
source share
4 answers

- , . 0- 4 ( , 0-15- ( 64 )) , 0 ( 0x00000FFF 0x0000FFFF, ) .

-. 0, () 1, - VM , . , "" VM. , - .

(, , , , , 0- .)

, Windows (post Win98) 64 KB 4 ? Wyzard , .

* : RE: 64 ? - -, Windows Core, , , , 64 , Windows 64 . ? , , , : http://blogs.msdn.com/b/oldnewthing/archive/2003/10/03/55239.aspx. . *

+4

C ++ NULL 0, 0 . , Windows , - .

, , , myarray[n], myarray null, mystruct->myfield, mystruct null. , , - .

+3

, , null . :

int startOffset = 1000; //start at 1000th element;
char* buffer = obtain();// happens to be null
for( int i = startOffset; buffer[i] != 0; i++ ) {
   //do stuff
}

, . , buffer , , , "".

0

, , , .

struct Foo {
    int a;
    inb b;
}* Bar = 0;

Bar->b = 0;

In int = 32bit compilers, member 'b' will contain 4 bytes in the structure, so Bar-> b will try to access address 0x00000004.

0
source

Source: https://habr.com/ru/post/1776153/


All Articles