Skip to content

Commit 7c165f7

Browse files
authored
The _code field in an NSError is signed, not unsigned. (llvm#119764)
The NSError summary provider was fetching and printing the `_code` field as an unsigned integer, but it's defined to be an NSInteger, which is signed.
1 parent 409ca49 commit 7c165f7

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

lldb/source/Plugins/Language/ObjC/NSError.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ bool lldb_private::formatters::NSError_SummaryProvider(
6666
lldb::addr_t domain_location = ptr_value + 3 * ptr_size;
6767

6868
Status error;
69-
uint64_t code = process_sp->ReadUnsignedIntegerFromMemory(code_location,
70-
ptr_size, 0, error);
69+
int64_t code = process_sp->ReadSignedIntegerFromMemory(code_location,
70+
ptr_size, 0, error);
7171
if (error.Fail())
7272
return false;
7373

@@ -77,7 +77,7 @@ bool lldb_private::formatters::NSError_SummaryProvider(
7777
return false;
7878

7979
if (!domain_str_value) {
80-
stream.Printf("domain: nil - code: %" PRIu64, code);
80+
stream.Printf("domain: nil - code: %" PRIi64, code);
8181
return true;
8282
}
8383

@@ -98,11 +98,11 @@ bool lldb_private::formatters::NSError_SummaryProvider(
9898
StreamString domain_str_summary;
9999
if (NSStringSummaryProvider(*domain_str_sp, domain_str_summary, options) &&
100100
!domain_str_summary.Empty()) {
101-
stream.Printf("domain: %s - code: %" PRIu64, domain_str_summary.GetData(),
101+
stream.Printf("domain: %s - code: %" PRIi64, domain_str_summary.GetData(),
102102
code);
103103
return true;
104104
} else {
105-
stream.Printf("domain: nil - code: %" PRIu64, code);
105+
stream.Printf("domain: nil - code: %" PRIi64, code);
106106
return true;
107107
}
108108
}

lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSError.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ def test_nserror_with_run_command_no_const(self):
2323
self.appkit_tester_impl(self.nserror_data_formatter_commands, False)
2424

2525
def nserror_data_formatter_commands(self):
26-
self.expect("frame variable nserror", substrs=['domain: @"Foobar" - code: 12'])
26+
self.expect(
27+
"frame variable nserror", substrs=['domain: @"Foobar" - code: -1234']
28+
)
2729

2830
self.expect(
29-
"frame variable nserrorptr", substrs=['domain: @"Foobar" - code: 12']
31+
"frame variable nserrorptr", substrs=['domain: @"Foobar" - code: -1234']
3032
)
3133

3234
self.expect("frame variable nserror->_userInfo", substrs=["2 key/value pairs"])

lldb/test/API/functionalities/data-formatter/data-formatter-objc/main.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ int main(int argc, const char *argv[]) {
618618

619619
NSDictionary *error_userInfo = @{@"a" : @1, @"b" : @2};
620620
NSError *nserror = [[NSError alloc] initWithDomain:@"Foobar"
621-
code:12
621+
code:-1234
622622
userInfo:error_userInfo];
623623
NSError **nserrorptr = &nserror;
624624

0 commit comments

Comments
 (0)