Does Windows XP automatically initialize arrays to zero?

Niko

We've recently discovered a serious bug in our software that was caused by assuming that a dynamically allocated array was initialized to zero (while it wasn't). So the problem was something like this:

int* foo = new int[1];
foo[0] += 10;

I'm now trying to estimate the impact of this since we also recently had a few changes in our environment: We started using new processing units which run a different OS (Win XP before, which are still used, now in addition to that some new units running Win 8).

There appears to be no problem with the computations running on the Win XP machines, but on Win 8 the same binaries produce gibberish. So the compiler does not initialize these arrays (these were optimized builds) but it seems like Windows XP does initialize newly allocated memory to zeros (while Windows 8 does not). Is this somewhere documented? Can I trust in this so that I can assume this problem did not affect all computations previously executed on the Win XP machines?

MSalters

Zero initialization of pages new to the process happens in all Windows versions. It would be a security failure to do otherwise. However, depending on address space layout, new requests may or may not be satisfied by recycled allocations. And since Vista, address space is randomized.

But it's indeed possible that due to some event outside your control, you may have gotten a recycled memory page from new int[] even on XP. That could even have been a page initially allocated to your process in reaction to some OS call you made, e.g. to convert an ANSI string to UTF-16 when you called MessageBoxA(). You really can't assume that all memory that's new to you is new to your process.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does C++ initialize integers to zero automatically?

From Dev

How does the compiler initialize local arrays with a default value of zero on the stack?

From Dev

Initialize jagged arrays of different length automatically

From Dev

istream_iterator Does Not Zero-Initialize

From Dev

Calloc does not initialize entire memory block to zero

From Dev

Does C initialize structure padding to zero?

From Dev

Does C initialize structure padding to zero?

From Dev

Why the command does not run on Windows XP?

From Dev

Does Java Program on XP will run as it is on windows 7

From Dev

Why the command does not run on Windows XP?

From Dev

Automatically run PHP script in task scheduler windows xp

From Dev

Does OpenCL always zero-initialize device memory?

From Dev

Does default constructor zero-initialize member array variable?

From Dev

QApplication::setWindowIcon works on Windows XP, but does not work on Windows 7

From Dev

What exactly does safe mode do? (Windows 7 and XP)

From Dev

SerialPort object does not receive any data under Windows XP

From Dev

How does alignment work with pointers to zero-sized arrays?

From Dev

How does this read a 'zero' when comparing two arrays?

From Dev

Zero and initialize a C structure

From Dev

Initialize vector to zero

From Dev

The Windows 10 onscreen keyboard does not launch automatically

From Dev

Time does not update automatically on Windows 10

From Dev

Does Windows automatically load files on the desktop?

From Dev

JAVASCRIPT: does Arrays constructor automatically have a variable called arguments?

From Dev

Dual-booting Windows 7 and Windows XP -- why does Windows 7 boot time differ?

From Dev

Automatically initialize object in Scala

From Dev

Does Windows automatically checks in the background stored Windows credentials?

From Dev

Why does System.Drawing.Image.GetPropertyItem behave differently on Windows XP / 2003 compared to Windows 7

From Dev

How much more RAM does Windows 7 use than Windows XP?

Related Related

  1. 1

    Does C++ initialize integers to zero automatically?

  2. 2

    How does the compiler initialize local arrays with a default value of zero on the stack?

  3. 3

    Initialize jagged arrays of different length automatically

  4. 4

    istream_iterator Does Not Zero-Initialize

  5. 5

    Calloc does not initialize entire memory block to zero

  6. 6

    Does C initialize structure padding to zero?

  7. 7

    Does C initialize structure padding to zero?

  8. 8

    Why the command does not run on Windows XP?

  9. 9

    Does Java Program on XP will run as it is on windows 7

  10. 10

    Why the command does not run on Windows XP?

  11. 11

    Automatically run PHP script in task scheduler windows xp

  12. 12

    Does OpenCL always zero-initialize device memory?

  13. 13

    Does default constructor zero-initialize member array variable?

  14. 14

    QApplication::setWindowIcon works on Windows XP, but does not work on Windows 7

  15. 15

    What exactly does safe mode do? (Windows 7 and XP)

  16. 16

    SerialPort object does not receive any data under Windows XP

  17. 17

    How does alignment work with pointers to zero-sized arrays?

  18. 18

    How does this read a 'zero' when comparing two arrays?

  19. 19

    Zero and initialize a C structure

  20. 20

    Initialize vector to zero

  21. 21

    The Windows 10 onscreen keyboard does not launch automatically

  22. 22

    Time does not update automatically on Windows 10

  23. 23

    Does Windows automatically load files on the desktop?

  24. 24

    JAVASCRIPT: does Arrays constructor automatically have a variable called arguments?

  25. 25

    Dual-booting Windows 7 and Windows XP -- why does Windows 7 boot time differ?

  26. 26

    Automatically initialize object in Scala

  27. 27

    Does Windows automatically checks in the background stored Windows credentials?

  28. 28

    Why does System.Drawing.Image.GetPropertyItem behave differently on Windows XP / 2003 compared to Windows 7

  29. 29

    How much more RAM does Windows 7 use than Windows XP?

HotTag

Archive