Skip to content

Possible Over-Iteration in PrettyBytes #139

Open
@VaslD

Description

@VaslD

I was looking for a not %02x way of converting binary to hex String, and I stumbled upon the implementation in PrettyBytes.swift.

self.regions.forEach { (_) in
for i in self {
hexChars[Int(offset * 2)] = itoh((i >> 4) & 0xF)
hexChars[Int(offset * 2 + 1)] = itoh(i & 0xF)
offset += 1
}
}

I'm not 100% sure about the Sequence conformance of non-contiguous DataProtocol, but it seemed to me that the self on line 46 should be the ignored parameter $0 (or maybe eliminate the region logic since looping over self most likely would have taken non-contiguous memory regions into account?), otherwise the code reads:

For each segment of the data buffer, loop over the entirety of data buffer and convert each byte to two hex chars.

Unless non-contiguous DataProtocol has non-stable indices and iterators, this code will over/re-iterate the data buffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions