Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when manually defining file encoding #36

Closed
xanderdunn opened this issue Apr 27, 2013 · 2 comments
Closed

Crash when manually defining file encoding #36

xanderdunn opened this issue Apr 27, 2013 · 2 comments

Comments

@xanderdunn
Copy link

I get an EXC_BAD_ACCESS crash when I use this:

NSInputStream *inputStream = [[NSInputStream alloc]
                                initWithFileAtPath:csvFilePath];
CHCSVParser *parser = [[CHCSVParser alloc]
                         initWithInputStream:inputStream
                         usedEncoding:NSUTF8StringEncoding
                         delimiter:','];

The crash occurs at line 119 of CHCSVParser.m, which is if (encoding == NULL || *encoding == 0) {

I am running all of this off the main thread, but I suspect that ought to be fine. Everything works fine off the main thread when I use initWithContentsOfCSVFile instead of the above.

My CHCSVParser.h/m are identical to GitHub's current master :head with the exception that I have included the code from #33, which simply provides a toggle for whitespace stripping and should have no effect on this.

I will upload the CSV file I am using and post a link as soon as possible. However, I don't think this error should be at all related to the CSV file, should it?

@davedelong
Copy link
Owner

Instead of:

CHCSVParser *parser = [[CHCSVParser alloc]
                     initWithInputStream:inputStream
                     usedEncoding:NSUTF8StringEncoding
                     delimiter:','];

You should be doing:

NSString encoding = NSUTF8StringEncoding;
CHCSVParser *parser = [[CHCSVParser alloc]
                     initWithInputStream:inputStream
                     usedEncoding:&encoding
                     delimiter:','];

Yeah, it's kind of weird, sorry. I didn't want an explosion of initializers, so if you know the encoding before-hand, it needs to be passed by-ref.

@xanderdunn
Copy link
Author

That worked. Thanks. Definitely include this in the README and CHCSVParser.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants