Skip to content

Commit

Permalink
Off by one.
Browse files Browse the repository at this point in the history
Previously this gave:
```
; ./build/bin/re -r literal -G 3 abc
; ./build/bin/re -r literal -G 4 abc
abc
;
```
and now -G 3 does construct "abc" (not including the newline, which is a property of the printing, not of the constructed string):
```
; ./build/bin/re -r literal -G 3 abc
abc
; ./build/bin/re -r literal -G 4 abc
abc
;
```

and:
```
; ./build/bin/re -r native -G 3 '^x+$'
x
xx
xxx
```

Spotted by @pierreganty (#478), thank you
  • Loading branch information
katef committed Aug 24, 2024
1 parent edeb291 commit 3769f77
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libfsm/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>

#include <fsm/fsm.h>
#include <fsm/pred.h>
Expand Down Expand Up @@ -139,6 +140,11 @@ int
fsm_generate_matches(struct fsm *fsm, size_t max_length,
fsm_generate_matches_cb *cb, void *opaque)
{
if (max_length == 0) {
errno = EINVAL;
return 0;
}

INIT_TIMERS();
TIME(&pre);
int res = gen_init_outer(fsm, max_length, cb, opaque, false, 0);
Expand Down Expand Up @@ -562,8 +568,8 @@ sfs_step_edges(struct gen_ctx *ctx, struct gen_stack_frame *sf)
sf->u.step_edges.initialized = true;
}

if (ctx->buf_used + ctx->sed[sf->s_id] >= ctx->max_length) {
LOG(2, "PRUNING due to max length: used:%zu + sed[%d]:%u >= max_length:%zu\n",
if (ctx->buf_used + ctx->sed[sf->s_id] > ctx->max_length) {
LOG(2, "PRUNING due to max length: used:%zu + sed[%d]:%u > max_length:%zu\n",
ctx->buf_used, sf->s_id, ctx->sed[sf->s_id], ctx->max_length);
sf->t = GEN_SFS_LEAVING_STATE;
return true;
Expand Down

0 comments on commit 3769f77

Please sign in to comment.