EXC_BAD_ACCESS on NSLog with no string formatting

后端 未结 4 1888
梦如初夏
梦如初夏 2021-02-19 17:56

I\'m getting an EXC_BAD_ACCESS (or a malloc error) on the following line of code:

NSLog(@\"Points:\");  

Which makes zero sense to me, as it

相关标签:
4条回答
  • 2021-02-19 18:38

    Old question but in Swift you'll get this issue if you are logging an encoded URL which contains '%' - For example:

    NSLog("My long Encoded URL: \(myLongUrlVar)")
    

    Instead, it will work with params:

    NSLog("My long Encoded URL: %@", myLongUrlVar)
    
    0 讨论(0)
  • 2021-02-19 18:48

    First thing I would try (after zombie hunting or perhaps before in this case) is to clear out the build directories and do a fresh rebuild. Sometimes left over cruft from prior builds can cause strange problems.

    0 讨论(0)
  • 2021-02-19 18:49

    there are % in string, replace % to %%

    NSLog([message stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]);
    
    0 讨论(0)
  • 2021-02-19 18:50

    In the comments I suggested:

    The problem is not with NSLog. The problem is probably that some memory is getting smashed and that is causing the crash in NSLog. It would probably help if you could break down that method you're using to make it easier to read, perhaps even separating the functionality into a new object. Also, avoid the use of magic numbers (3 & 6).

    It appears that @haldean went with this suggestion and tracked down the problem. I can't claim credit for actually doing the hard work of tracking down the problem, but I'm happy the suggestion helped.

    0 讨论(0)
提交回复
热议问题