Skip to content

Fixes a shadowed variable in the system time zone initializer. #152

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

Merged
merged 1 commit into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion CoreFoundation/NumberDate.subproj/CFTimeZone.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,6 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) {
}
ret = readlink(TZZONELINK, linkbuf, sizeof(linkbuf));
if (0 < ret) {
CFStringRef name;
linkbuf[ret] = '\0';
if (strncmp(linkbuf, TZZONEINFO, sizeof(TZZONEINFO) - 1) == 0) {
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf + sizeof(TZZONEINFO) - 1, strlen(linkbuf) - sizeof(TZZONEINFO) + 1, kCFStringEncodingUTF8, false);
Expand Down
13 changes: 13 additions & 0 deletions TestFoundation/TestNSTimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
import Glibc
#else
import SwiftFoundation
import SwiftXCTest
import Darwin
#endif


Expand All @@ -25,6 +27,7 @@ class TestNSTimeZone: XCTestCase {
return [
("test_abbreviation", test_abbreviation),
("test_initializingTimeZoneWithOffset", test_initializingTimeZoneWithOffset),
("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime),
]
}

Expand All @@ -39,4 +42,14 @@ class TestNSTimeZone: XCTestCase {
let seconds = tz?.secondsFromGMTForDate(NSDate())
XCTAssertEqual(seconds, -14400)
}

func test_systemTimeZoneUsesSystemTime() {
tzset();
var t = time(nil)
var lt = tm()
localtime_r(&t, &lt)
let zoneName = NSTimeZone.systemTimeZone().abbreviation ?? "Invalid Abbreviation"
let expectedName = NSString(CString: lt.tm_zone, encoding: NSASCIIStringEncoding)?.bridge() ?? "Invalid Zone"
XCTAssertEqual(zoneName, expectedName)
}
}