Skip to content
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

"Index out of range" - error occurs when passing user properties to message #576

Open
ltAldoRaine opened this issue Feb 27, 2024 · 0 comments

Comments

@ltAldoRaine
Copy link

Hello, I'm trying to pass user properties to my publish message, but my application crashes with the error - Index Out of Range.

The error occurs in this method.

func unsignedByteToString(data:[UInt8], offset:Int) -> (resStr: String, newOffset: Int)?{
    var newOffset = offset

    if offset + 1 > data.count {
        return nil
    }

    var length = 0
    let comRes = integerCompute(data: data, formatType: formatInt.formatUint16.rawValue, offset: newOffset)
    length = comRes!.res
    newOffset = comRes!.newOffset


    var stringData = Data()
    for _ in 0 ..< length {
        stringData.append(**data[newOffset]**) // here
        newOffset += 1
    }
    guard let res = String(data: stringData, encoding: .utf8) else {
        return nil
    }

    return (res, newOffset)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant