Join us at IRC!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Thursday, May 24, 2012
Navigation
Members Online
Total Online: 33
Web Spiders: 13
Guests Online: 27
Members Online: 6

Registered Members: 70198
Newest Member: PenTest Laboratory
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Just out of curiosity

ellipsis
Member



Posts: 114
Location:
Joined: 13.06.09
Rank:
God
Posted on 29-07-10 00:36
The following code prints all environment variables among other things..

Can someone please elaborate to me why that is?


#include <iostream>
using namespace std;

string * GetArray()
{
string asdf[3] = { "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" };
return(asdf);
}

void foo(string array[], int size)
{
// for (int i = size; i >= 0; i--) /* for a different exception */
cout << array[1] << endl;
}

int main()
{
string * array = GetArray();
foo(array, 2); // <-- required for error

return(0);
}



GNU is NOT UNIX
Author

RE: Just out of curiosity

gregorian
Member



Posts: 109
Location: India
Joined: 28.06.10
Rank:
God
Posted on 29-07-10 02:28
It's full of errors and won't compile. Besides, you're returning the address of a local variable. When you get out of the function, we're not sure what the pointer is pointing to. if I were you, I'd disassemble it and look at the value dereferenced by the pointer after the function call completes. Maybe it's a list of environment variables?

Edited by gregorian on 29-07-10 02:34
Author

RE: Just out of curiosity

hellboundhackersok
Member



Posts: 353
Location:
Joined: 20.09.07
Rank:
God
Warn Level: 95
Posted on 29-07-10 08:11
ellipsis wrote:
The following code prints all environment variables among other things..

Can someone please elaborate to me why that is?


It doesn't.



Paint.NET Pwns
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.