     }
     var buffer = Array(
       count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
-    var result = s.getCString(&buffer, maxLength: 100,
-        encoding: NSUTF8StringEncoding)
+    let result = s.getCString(&buffer, maxLength: 100,
+      encoding: NSUTF8StringEncoding)
     expectTrue(result)
     expectTrue(equal(expectedStr, buffer))
   }
   if true {
+    // Limit buffer size with 'maxLength'.
     let bufferLength = 100
     var buffer = Array(
       count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
-    var result = s.getCString(&buffer, maxLength: 8,
-        encoding: NSUTF8StringEncoding)
+    let result = s.getCString(&buffer, maxLength: 8,
+      encoding: NSUTF8StringEncoding)
     expectFalse(result)
   }
   if true {
+    // String with unpaired surrogates.
     let illFormedUTF16: String = NonContiguousNSString([ 0xd800 ])
-    let bufferLength = 16
+    let bufferLength = 100
     var buffer = Array(
       count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
-    var result = s.getCString(&buffer, maxLength: 100,
+    let result = illFormedUTF16.getCString(&buffer, maxLength: 100,
       encoding: NSUTF8StringEncoding)
     expectFalse(result)
   }

  // This test might need to be adjusted for other systems.
  var s = "abc だくてん"
  if true {
    let bufferLength = 16
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    var result = s.getFileSystemRepresentation(&buffer, maxLength: 100)
    expectFalse(result)
  }
  if true {
    let bufferLength = 100
    var expectedStr = map("abc \u{305f}\u{3099}くてん\0".utf8) {
      CChar(bitPattern: $0)
    }

NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
  var s = "abc あかさた"
  if true {
    // The largest buffer that can not accomodate the string plus null terminator.
    let bufferLength = 16
    var buffer = Array(
      count: bufferLength, repeatedValue: CChar(bitPattern: 0xff))
    let result = s.getCString(&buffer, maxLength: 100,
      encoding: NSUTF8StringEncoding)
    expectFalse(result)
  }
  if true {
    // The smallest buffer where the result can fit.
    let bufferLength = 17
    var expectedStr = map("abc あかさた\0".utf8) { CChar(bitPattern: $0) }
    while (expectedStr.count != bufferLength) {
