0

I read, that pointers (in C), that are not initialized, could point to an address that contain data or program code from other programs. In the book it says, that this can cause damage.

Is this issue a problem with regards to modern operating systems? I know, that in Linux, there's virtual address space, so that addresses are only associated with a specific process. That way, pointers shouldn't point to addresses used by other processes? I don't know if that's true for windows, macOS or Unix.

Is it a serious issue nowadays?

-1

It's true for Windows, MacOS and Unix too. In the usual case on all of these systems an uninitialized pointer can only cause unexpected behaviour within the current process.

That's not to say that it can never happen. In all of those systems it is possible to arrange for a process to voluntarily share regions of memory with other processes (by using shmget/shmat or mmap), and in that case a bad pointer in one process could corrupt the shared data in a way that could cause other processes to misbehave.

  • The memory management unit (MMU) for all modern processors ensures there is no unintentional memory overlap between different user-space programs. More explicitly, it ensures there can be no unintentional memory overlap. – roaima Mar 27 at 20:06
  • @roaima That's why I used the word "voluntarily". When a program uses shmat to attach to a memory segment that is intended to be shared between several processes, there's nothing "unintentional" about that sharing. – ottomeister Mar 27 at 20:11
  • It's your first sentence. You're saying (agreeing) that uninitialised pointers can overwrite other processes? No. – roaima Mar 27 at 21:00
  • I'm replying to the OP's actual question (in his second paragraph) where he points out that Linux has a virtual memory system that limits damage to within the current process, and asks whether that is also true for Win/Mac/Unix. It is true. The second sentence in my answer should make my position clear: "[...] an uninitialized pointer can only cause unexpected behaviour within the current process". – ottomeister Mar 27 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.