Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:49:11+00:00 2026-06-01T18:49:11+00:00

I recently started testing my application using a release build (Manage Schemes and set

  • 0

I recently started testing my application using a release build (Manage Schemes and set run from debug to release). What I’ve noticed is that occasionally I get the following error pop up inside the stream method and I can’t seem to figure out a way to find the error. This works perfectly in debug mode, but in the release build I am not getting any notification aside from the SIGABRT message. Nor am I aware of how to check the crash logs on the simulator to see what the issue can be. Below I’ve attached a stack trace of the crash:

#0  0x918749c6 in __pthread_kill ()
#1  0x916c0f78 in pthread_kill ()
#2  0x916b1ce3 in __abort ()
#3  0x916ae64a in __stack_chk_fail ()
#4  0x00006d0d in -[MainViewController processMessage:len:] (_cmd=0x9ceb9, msg=0xdfd7004 "Login="User" Pass="Pass" Id="1234" PlayerId="345" Location="12,35" Color="Red" PlayerId="65" Location="180,0" Color="Blue" PlayerId="29" Location="0,200" Color="..., len=333295) at /Users/seb/Desktop/Tutorials/Networking/MainViewController.m:850
#5  0x000044b3 in -[MainViewController stream:handleEvent:] (_cmd=0x17a0410, stream=<value temporarily unavailable, due to optimizations>, eventCode=<value temporarily unavailable, due to optimizations>) at /Users/seb/Desktop/Tutorials/Networking/MainViewController.m:260
#6  0x01716501 in _inputStreamCallbackFunc ()
#7  0x016e606d in _signalEventSync ()
#8  0x016e67ca in _cfstream_solo_signalEventSync ()
#9  0x016e5e71 in _CFStreamSignalEvent ()
#10 0x016e6727 in CFReadStreamSignalEvent ()
#11 0x020083ad in SocketStream::dispatchSignalFromSocketCallbackUnlocked ()
#12 0x01f64191 in SocketStream::socketCallback ()
#13 0x01f640a1 in SocketStream::_SocketCallBack_stream ()
#14 0x016b3e44 in __CFSocketPerformV0 ()
#15 0x0171997f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#16 0x0167cb73 in __CFRunLoopDoSources0 ()
#17 0x0167c454 in __CFRunLoopRun ()
#18 0x0167bdb4 in CFRunLoopRunSpecific ()
#19 0x0167bccb in CFRunLoopRunInMode ()
#20 0x0226f879 in GSEventRunModal ()
#21 0x0226f93e in GSEventRun ()
#22 0x0066aa9b in UIApplicationMain ()
#23 0x0000201b in main (argc=1, argv=0xbffff5e0) at /Users/seb/Desktop/Tutorials/Networking/main.m:14

Case statement from stream:handleevent in where the crash happens:

case NSStreamEventHasBytesAvailable:
        {
            if (stream == inputStream)
            {
                NSLog(@"NSStreamEventHasBytesAvailable");

                uint8_t buffer[4096];
                unsigned int len = 0;
                NSInputStream* inputstream = (NSInputStream*)stream;
                len = [inputstream read:buffer maxLength:sizeof(buffer)];

                // Check if our stream is still valid
                if([inputstream streamError] != nil)
                {
                    //We lost our connection to the host
                    NSError *theError = [stream streamError];
                    [self setConnectError:[NSString stringWithFormat:@"Error %i: %@",
                                                            [theError code], [theError localizedDescription]]];

                    break;
                }

                [streamIncomingData appendBytes:buffer length:len];

                int processedBytes = 0;
                while (true)
                {
                    if ([streamIncomingData length] >= processedBytes + sizeof(uint32_t))
                    {
                        const char* bufferstart = ((const char*)[streamIncomingData mutableBytes]) + processedBytes;
                        uint32_t sz_n;
                        memcpy(&sz_n, bufferstart, sizeof(sz_n));
                        uint32_t sz_h = htonl(sz_n);

                        if ([streamIncomingData length] >= processedBytes + sz_h + sizeof(uint32_t))
                        {
                            [self processMessage:bufstart + sizeof(uint32_t) len:sz_h];
                            processedBytes += sz_h + sizeof(uint32_t);
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (processedBytes)
                {
                    if (processedBytes < [streamIncomingData length])
                    {
                        NSMutableData *newdata = [NSMutableData dataWithBytes:[streamIncomingData bytes] + processedBytes length:[streamIncomingData length] - processedBytes];
                        [streamIncomingData setData:newdata];
                    }
                    else
                    {
                        [streamIncomingData setLength:0];
                    }
                }
            }

            break;
        }

processMessage method:

- (void)processMessage:(const char*)msg len:(int)len
{
    NSLog(@"processMessage start (%d)", len);
    {
        char buffer[len + 1];
        memcpy(buffer, msg, len);
        buffer[len + 1] = '\0';
        NSLog(@"%s", buffer);
    }

    NSLog(@"processMessage end");
}

Any advice is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:49:12+00:00Added an answer on June 1, 2026 at 6:49 pm

    You have corrupted the stack by overflowing the buffer by trying to assign the null terminator outside of the bounds len + 1. The correct code would be:

        char buffer[len + 1];
        memcpy(buffer, msg, len);
        buffer[len] = '\0';
        NSLog(@"%s", buffer);
    

    What you were doing was undefined behavior and combining undefined behavior with the optimizations that are done for release mode is most likely the reason you only saw this issue in release mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently started testing MongoDB via shell and via PyMongo. I've noticed that returning
I have recently started testing for my android application using Instrumentation framework. I have
FireWatir I recently started using Firewatir for testing, I followed all the required steps
I recently started using AutoFixture library (http://autofixture.codeplex.com/) for Unit Testing and I quite like
I've recently started using git, and also begun unit testing (using Python's unittest module).
I've just recently started using unit testing, and I understand some of the main
I've recently started practising TDD and unit testing, with my main primers being the
I recently started using lcov to visualize my code coverage. It's a great tool.
I recently started looking into building web applications using .NET MVC and I stumbled
Ive recently started using CodeIgniter as I was searching for a very lightweight framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.