Created
May 23, 2011 18:29
-
-
Save wimleers/987233 to your computer and use it in GitHub Desktop.
Note that the array index that is used goes beyond the array's capacity. And thus it modifies the next variable in memory…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define uint unsigned int | |
#define TTW_NUM_GRANULARITIES 5 | |
class Weird { | |
public: | |
Weird() { | |
this->lastUpdate = 0; | |
for (int g = 0; g < TTW_NUM_GRANULARITIES; g++) | |
this->capacityUsed[g] = 0; | |
} | |
void increment() { this->lastUpdate++; } | |
void test() { | |
uint granularity = TTW_NUM_GRANULARITIES; | |
printf("before: %d\n", this->lastUpdate); | |
// Update this granularity's used capacity.. | |
this->capacityUsed[granularity] = 0; | |
printf("before: %d\n", this->lastUpdate); | |
} | |
protected: | |
uint capacityUsed[TTW_NUM_GRANULARITIES]; | |
uint lastUpdate; | |
}; | |
int main() { | |
Weird w; | |
w.increment(); | |
w.test(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment