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

Remove arbitrary padding limit #41

Merged
merged 1 commit into from
Oct 29, 2023

Conversation

Kixunil
Copy link
Collaborator

@Kixunil Kixunil commented Oct 27, 2023

When formatting a slice as hex an arbitrary limit of 512 chars was applied to decide whether to pad it. This was silent and surprising so this commit fixes it by removing the limit. It implements padding manually with moderate optimizations.

(The limit was introduced in #25 )

When formatting a slice as hex an arbitrary limit of 512 chars was
applied to decide whether to pad it. This was silent and surprising so
this commit fixes it by removing the limit. It implements padding
manually with moderate optimizations.
fmt::Alignment::Center =>
((width - string_len) / 2, (width - string_len + 1) / 2),
};
// Avoid division by zero and optimize for common case.
Copy link
Member

Choose a reason for hiding this comment

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

In 8569ee8:

Here and below I don't think there is any actual division by 0. There would be "dividing 0 by something" but this is harmless.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

chunk_len is 0 if the input to put_filler is 0. I actually got panics for that, unfortunately I wasn't smart enough to see it first. :)

Copy link
Member

Choose a reason for hiding this comment

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

Lol, me neither apparently :)

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 8569ee8

@apoelstra apoelstra merged commit 1c198dd into rust-bitcoin:master Oct 29, 2023
9 checks passed
@Kixunil Kixunil deleted the no-padding-limit branch October 29, 2023 17:51
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

Successfully merging this pull request may close these issues.

2 participants