Skip to content

fix serious bugs2#3

Merged
tcrypt25519 merged 2 commits intomainfrom
fix_serious_bugs2
Feb 14, 2026
Merged

fix serious bugs2#3
tcrypt25519 merged 2 commits intomainfrom
fix_serious_bugs2

Conversation

@tcrypt25519
Copy link
Owner

  • fix: Correctly validate month number.
  • fix: Replace memory-hungry parse function.

Copilot AI review requested due to automatic review settings February 14, 2026 17:10
@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 14, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  src/lib.rs  18% smaller
  src/types.rs  0% smaller

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tcrypt25519, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the date parsing logic to improve performance and reduce memory usage by eliminating unnecessary heap allocations during string splitting. Additionally, it enhances data validation by introducing an explicit check for invalid month numbers when constructing Day objects, leading to more robust date handling.

Highlights

  • Date Parsing Efficiency: Replaced the split().collect() method for parsing slash-delimited dates with a more memory-efficient, byte-by-byte parsing approach, avoiding heap allocations.
  • Month Validation: Implemented explicit validation for month numbers (0 or greater than 12) directly within the Day::new constructor, ensuring data integrity earlier in the process.
Changelog
  • src/lib.rs
    • Replaced the split().collect() approach for parsing month-first slash-delimited dates with a new parse_slash_date function.
    • Introduced parse_slash_date to handle MM/YYYY and MM/DD/YYYY formats using a strict byte-by-byte walk, avoiding heap allocations.
    • Removed the parse_month_year and parse_full_date helper functions.
    • Updated test_parse_with_whitespace to reflect the stricter parsing of spaces around separators.
    • Simplified the error assertion for "too many slashes" in tests.
  • src/types.rs
    • Added a check for month values (0 or >12) at the beginning of the Day::new constructor.
    • Updated the documentation for Day::new to include the new ParseError::InvalidMonth error.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two critical bugs in date parsing: adds missing month validation in Day::new() and replaces a memory-inefficient parsing implementation with a zero-allocation byte-by-byte parser.

Changes:

  • Add month range validation (0 or >12) in Day::new() to prevent invalid month values from being used in day-of-month calculations
  • Replace heap-allocating parse_month_year and parse_full_date functions with a single efficient parse_slash_date that uses byte-by-byte parsing
  • Update tests to reflect the stricter parsing behavior (no whitespace around separators)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/types.rs Adds month validation check in Day::new() before using month value for calculations
src/lib.rs Replaces two separate parsing functions with unified parse_slash_date that avoids heap allocation and strictly validates format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tcrypt25519 tcrypt25519 merged commit b04088c into main Feb 14, 2026
7 checks passed
@tcrypt25519 tcrypt25519 deleted the fix_serious_bugs2 branch February 14, 2026 17:13
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces two important fixes. First, it replaces a memory-intensive date parsing function with a more efficient, allocation-free byte-by-byte parser. This is a great performance improvement. Second, it adds a missing validation check for the month number in the Day::new constructor, improving the robustness of the type. The changes are well-implemented, but I've found a subtle bug in the new parse_slash_date function where it incorrectly slices the month string, which I've provided a fix for.


Ok(Self::Month { year, month })
}
let month_str = &s[..pos];
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There's a subtle bug here in how the month string is sliced. pos is currently the index of the / separator. Slicing with &s[..pos] correctly extracts the month digits. However, the pos variable is not updated to reflect the start of the month string, which is always 0. This can lead to incorrect parsing in some edge cases. To fix this, we should explicitly define the start of the month string.

Suggested change
let month_str = &s[..pos];
let month_str = &s[0..pos-1];

@tcrypt25519 tcrypt25519 restored the fix_serious_bugs2 branch February 22, 2026 01:12
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