Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/SVGBezierPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
NSArray * const pathRefs = CGPathsFromSVGString(svgString, &cgAttrs);
NSMutableArray<SVGBezierPath*> * const paths = [NSMutableArray arrayWithCapacity:pathRefs.count];
for(id pathRef in pathRefs) {
SVGBezierPath * const uiPath = [self bezierPathWithCGPath:(__bridge CGPathRef)pathRef];

Check warning on line 63 in Sources/SVGBezierPath.mm

View workflow job for this annotation

GitHub Actions / Primary

'bezierPathWithCGPath:' is only available on macOS 14.0 or newer [-Wunguarded-availability-new]

Check warning on line 63 in Sources/SVGBezierPath.mm

View workflow job for this annotation

GitHub Actions / Primary

incompatible pointer types initializing 'SVGBezierPath *const __strong' with an expression of type 'NSBezierPath * _Nonnull' [-Wincompatible-pointer-types]
uiPath->_svgAttributes = [cgAttrs attributesForPath:(__bridge CGPathRef)pathRef] ?: @{};
uiPath.lineWidth = uiPath->_svgAttributes[@"stroke-width"] ? [uiPath->_svgAttributes[@"stroke-width"] doubleValue] : 1.0;
[paths addObject:uiPath];
Expand Down Expand Up @@ -91,6 +91,10 @@
NSParameterAssert(attributes);

SVGBezierPath *path = [self copy];
if (path == nil) {
// Fallback if copy returns nil, ensure non-null return.
path = self;
Comment on lines +95 to +96
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

falling back to self when self copy returns nil breaks the contract of this method, because callers expect a distinct instance. how about:

Suggested change
// Fallback if copy returns nil, ensure non-null return.
path = self;
// Fallback if copy returns nil, ensure non-null return.
SVGBezierPath *newPath = [SVGBezierPath bezierPathWithCGPath:self.CGPath];
newPath.lineWidth = self.lineWidth;
newPath.flatness = self.flatness;
newPath.miterLimit = self.miterLimit;
path = newPath;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I like this fallback solution much better.

}
if (path) {
if (path->_svgAttributes.count > 0) {
path->_svgAttributes = [path->_svgAttributes mutableCopy];
Expand Down
Loading