-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#20 Don't read digits beyond the digits boundary
- Loading branch information
Showing
2 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,7 @@ public class PostgreSQLResultFetcher: ResultFetcher { | |
|
||
case .numeric: | ||
// Numeric is a sequence of Int16's: number of digits, weight, sign, display scale, numeric digits | ||
// https://www.postgresql.org/message-id/[email protected] | ||
let sign = PostgreSQLResultFetcher.int16NetworkToHost(from: value.advanced(by: 4)) | ||
if sign == -16384 { // 0xC000 | ||
return "NaN" | ||
|
@@ -171,15 +172,20 @@ public class PostgreSQLResultFetcher: ResultFetcher { | |
|
||
if weight >= 0 { | ||
for i in 0 ... weight { | ||
let digitsAsInt16 = PostgreSQLResultFetcher.int16NetworkToHost(from: currentDigitData) | ||
if i == 0 { | ||
result += String(digitsAsInt16) | ||
if currentDigitNumber < numberOfDigits { | ||
let digitsAsInt16 = PostgreSQLResultFetcher.int16NetworkToHost(from: currentDigitData) | ||
if i == 0 { | ||
result += String(digitsAsInt16) | ||
} | ||
else { | ||
result += String(format: "%04d", digitsAsInt16) | ||
} | ||
currentDigitData = currentDigitData.advanced(by: 2) | ||
currentDigitNumber = i + 1 | ||
} | ||
else { | ||
result += String(format: "%04d", digitsAsInt16) | ||
result += "0000" | ||
} | ||
currentDigitData = currentDigitData.advanced(by: 2) | ||
currentDigitNumber = i + 1 | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters