Skip to content

Suspicious mismatch between comments and code #499

@Shnatsel

Description

@Shnatsel

The comment indicates len-(STD_MIN_MATCH-1), note the -1, while the actual code uses +1:

/* Try hash head at len-(STD_MIN_MATCH-1) position to see if we could get
* a better cur_match at the end of string. Using (STD_MIN_MATCH-1) lets
* us include one more byte into hash - the byte which will be checked
* in main loop now, and which allows to grow match by 1.
*/
let [scan0, scan1, scan2, ..] = scan[len - (STD_MIN_MATCH + 1)..] else {
panic!("index out of bounds");
};

Changing the code to -1 to match by the comment doesn't break any tests. So this codepath might be untested?

FWIW upstream zlib-ng also has this mismatch:

https://github.com/zlib-ng/zlib-ng/blob/c2712b8a345191f6ed79558c089777df94590087/match_tpl.h#L204-L209

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions