Skip to content

Match of \\s* on empty string reports pos == -1, i.e., no match, while it should report pos == 0 and matchlength == 0 #88

@grigory-rechistov-intel

Description

Consider this program, which tries to match zero or more space characters in a string of length zero:

// $ cat empty-str.c
#include "re.h"
#include "assert.h"

int main() {
    int matchlength = 0;
    int pos = re_match("\\s*", "", &matchlength);
    assert(pos != -1);
    return 0;
}

When compiled with re.c and executed, the assertion fails:

$ gcc empty-str.c re.c
$ ./a.out
a.out: empty-str.c:7: main: Assertion `pos != -1' failed.
Aborted (core dumped)

It is an interesting question about what the result of a successful match for an empty string should be. My take on it is that it should not report a failure for matching (i.e. the return value must not be negative), but the length of the match should be zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions