tags:

views:

331

answers:

1

For some reason excode is throwing this error when I try to cin into a string.

test(5640) malloc: * error for object 0x1000041c0: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug Program received signal: “SIGABRT”. sharedlibrary apply-load-rules all

Here is the code that produced that:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string hello;

    cout << "Enter a string";
    cin >> hello;

    return 0;

}

So does anybody have a solution?

A: 

According to this forum: http://discussions.apple.com/message.jspa?messageID=10236050#10236050

Technically, that is a warning message, not an error. This is a bug in the GCC C++ library. Remind me again why I don't write C++ code anymore. You would think in 2009 they would have silly things like this fixed.

You could avoid this by making sure your hello variable is initialized to something to start with.

Or, you can turn off the pedantic warnings. Select your debug target and double click it or Command-i. Scroll down to "GCC 4.2 - Preprocessing". Select "Preprocessor Macros" and delete it. You will no longer get the warning message. You will still be freeing unallocated memory, but you can complain to GCC about that.

Josh