From 66d9be2651e0973c1cba77525c2e9bb49625200c Mon Sep 17 00:00:00 2001 From: Alexander Manzer Date: Tue, 14 Nov 2023 10:32:05 +0100 Subject: [PATCH] ios: use a default error text instead of crashing Because `e.what()` returns `nil` sometimes, what is causing a crash when initializing the dictionary. --- wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm b/wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm index c8594b9a58..433994fb59 100644 --- a/wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm +++ b/wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm @@ -76,10 +76,10 @@ -(CGImageRef)encode:(std::wstring)content return [self inflate:&bitMatrix]; } catch(std::exception &e) { if (error != nil) { - NSDictionary *userInfo = @{ - NSLocalizedDescriptionKey: [[NSString alloc] initWithUTF8String:e.what()] - }; - *error = [[NSError alloc] initWithDomain:ZXIErrorDomain code:ZXIWriterError userInfo:userInfo]; + const char *errorCString = e.what(); + NSString *errorDescription = errorCString ? [NSString stringWithUTF8String:errorCString] : @"Unknown error"; + NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: errorDescription }; + *error = [NSError errorWithDomain:ZXIErrorDomain code:ZXIWriterError userInfo:userInfo]; } return nil; }