Skip to content
This repository was archived by the owner on Sep 19, 2019. It is now read-only.

fix(deser): fix indexing into str bug#62

Merged
niklasad1 merged 3 commits into
masterfrom
fix-deserialize-str
Feb 8, 2019
Merged

fix(deser): fix indexing into str bug#62
niklasad1 merged 3 commits into
masterfrom
fix-deserialize-str

Conversation

@niklasad1
Copy link
Copy Markdown
Contributor

str consist of unicode characters which can be between 1-4 bytes long and indexing assuming that all are 1 byte may panic

@niklasad1 niklasad1 requested a review from tomusdrw February 7, 2019 16:16
`str` consist of unicode characters which can be between 1-4 bytes long and indexing assuming that all are 1 byte may
panic
@niklasad1 niklasad1 force-pushed the fix-deserialize-str branch from bb7e7dc to dcd7571 Compare February 8, 2019 07:49
Copy link
Copy Markdown
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment thread serialize/src/lib.rs Outdated
if v.len() < 2 || &v[0..2] != "0x" {
// TODO: replace `v.starts_with("0x")` with `v.as_bytes()[0..2] != ['0' as u8, 'x' as u8]
// if `starts_with` is too slow
if v.len() < 2 || !v.starts_with("0x") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starts_with should suffice.

* Remove needless `len()`
* Cast raw `u8` to char for more human-friendly error message
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants