Skip to content

Commit

Permalink
fix(android): Fixed a crash with empty attributes values.
Browse files Browse the repository at this point in the history
Fixes #81.
  • Loading branch information
Skyost committed Jan 20, 2024
1 parent c8ff488 commit 87d8d60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class BonsoirService(
) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
for (attribute in service.attributes.entries) {
attributes[attribute.key] = String(attribute.value)
attributes[attribute.key] = if (attribute.value == null) "" else String(attribute.value)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class TXTRecord {
Log.d("TXTRecord", "Unable to query for a TXT record. Will now retry with a different port...")
return resolveTXTRecord(service, PORT)
}
}
catch (ex: Exception) {
} catch (ex: Exception) {
ex.printStackTrace()
}
return null
Expand Down Expand Up @@ -206,7 +205,9 @@ class TXTRecord {
var length: Int
while (true) {
length = dataInputStream.readUnsignedByte()
if (length == 0) return result.toString()
if (length == 0) {
return result.toString()
}
if (length and 0xc0 == 0xc0) {
// this is a compression method, the remainder of the string is a pointer to elsewhere in the packet
// adjust the stream boundary and repeat processing
Expand All @@ -225,7 +226,9 @@ class TXTRecord {
}
val segment = ByteArray(length)
dataInputStream.readFully(segment)
if (dot) result.append('.')
if (dot) {
result.append('.')
}
dot = true
result.append(String(segment))
if (result.length > packetLength) {
Expand All @@ -246,7 +249,7 @@ class TXTRecord {
* populated data structures. When no such answer is present in the packet, fields will be
* `null`.
*/
data class TXTRecordData (
data class TXTRecordData(
/**
* The service FQDN.
*/
Expand Down

0 comments on commit 87d8d60

Please sign in to comment.