Ticket #11026: trac_11026-fix-parse-error.patch

File trac_11026-fix-parse-error.patch, 1.1 KB (added by iandrus, 9 years ago)
  • sage/ext/mac-app/AppController.m

    # HG changeset patch
    # User Ivan Andrus <darthandrus@gmail.com>
    # Date 1358511781 -3600
    # Node ID d7923146097712fef8c3d021db6c13618c781d77
    # Parent  a9a78f185ebdb6bd53282bbefb78782d5e8094ff
    Trac 11026: Fix parsing of port number -- could fail depending on the contents of memory
    
    diff --git a/sage/ext/mac-app/AppController.m b/sage/ext/mac-app/AppController.m
    a b  
    153153        if (status == 0) {
    154154            // Parse the output
    155155            NSData *data = [[taskPipe fileHandleForReading] readDataToEndOfFile];
    156             const int p = [[NSString stringWithUTF8String:[data bytes]] intValue];
     156            NSString* s = [[NSString alloc] initWithBytes:[data bytes]
     157                                                   length:[data length]
     158                                                 encoding:NSUTF8StringEncoding];
     159            const int p = [s intValue];
     160            [s release];
    157161            [self serverStartedWithPort:p];
    158162        } else {
    159163            // We failed, so tell the user