naoyamakino / unsafe.cs Goto Github PK
View Code? Open in Web Editor NEWWrite a short C♯ program that uses pointers to violate C♯ array-bounds checking and crash your program.
Home Page: http://www.cs.sfu.ca/CC/383/ted/383-10-3/OutOfRange.html
Write a short C♯ program that uses pointers to violate C♯ array-bounds checking and crash your program.
Home Page: http://www.cs.sfu.ca/CC/383/ted/383-10-3/OutOfRange.html
/* * CMPT383 Assignment 03 * Naoya Makino * http://www.cs.sfu.ca/CC/383/ted/383-10-3/OutOfRange.html * October 03, 2010 */ Description Write a short C♯ program that uses pointers to violate C♯ array-bounds checking and crash your program. The crash will typically take the form of a C♯ exception, although if you're really lucky your program will just crash before it can raise an exception. There is no guaranteed value that will always crash your program. You will have to experiment a bit to see how badly you have to violate the array bounds to cause your program to crash. The details Your program should: Allocate a small array of integers. In an unsafe routine or code sequence use a fixed statement to assign a pointer to the first element of that array. Assign to an element outside the actual array. For example, if your array had only three elements, use the pointer to assign to the nonexistent fourth element. Define the index of the element you will access as a const variable. You will need to experiment with values of this constant, trying different ones until you get one large enough to consistently crash your program. Start with the routine Test2. But this routine includes more than you need, so be sure to delete the parts that don't relate to this assignment. The body of the solution to this assignment can be written in five lines, not counting curly braces. I described the fixed and unsafe keywords in class and the examples linked above should give you enough framework to get you started with them. I did not describe the two pointer operators you will need: getting the address of the first element of an array and indexing through a pointer ([ ]). Using them is simple enough: To get the address of the first element of an array, simply refer to the name of the array: int* p = myIntArray. This will have to be done within a fixed statement. Once you have a pointer to an array, you can index it just like the original array. For example, given the pointer p defined above, you access the second element of array myIntArray by writing p[1]. The essence of this assignment is demonstrating how unsafe access using pointers allows you to bypass dynamic checks that C♯ does on regular (safe) array indexing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.