Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3750

NSCopying copyWithZone: implementation does not check isSet

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.10.0
    • Component/s: Cocoa - Compiler
    • Labels:
      None

      Description

      The NSCopying copyWithZone: implementation does not check isSet. This causes the copy not to be a true copy, since all the isSet properties will be set to YES on the newly copied object.

      Note, updating to provide some more clarity:

      In this example, it's fixed:

      - (instancetype) copyWithZone:(NSZone *)zone
      {
        Foo * val = [Foo new];
        if (_nameIsSet)
        {
          val.name = [self.name copy];
        }
        return val;
      }
      

      Without the if check on _nameIsSet, the newly copied object will have _nameIsSet set to YES but with a nil name.

      - (void) setName: (NSString *) name {
        _name = name;
        _nameIsSet = YES;
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                zmanfx Zach Howe
                Reporter:
                zmanfx Zach Howe
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: