Skip to content

Commit 041461e

Browse files
committed
[notcurses][input] handle non-matches in escape trie properly
dankamongmen/notcurses@dadd5d3
1 parent a5d8ee1 commit 041461e

7 files changed

+18
-13
lines changed

src/third-party/notcurses/src/lib/automaton.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ int walk_automaton(automaton* a, struct inputctx* ictx, unsigned candidate,
556556
a->state = a->escapes;
557557
return 0;
558558
}
559+
if(e == NULL){ // we're not in the trie
560+
return -1;
561+
}
559562
if(e->ntype == NODE_STRING){
560563
if(candidate == 0x1b || candidate == 0x07){
561564
a->state = e->trie[candidate];
@@ -570,6 +573,7 @@ int walk_automaton(automaton* a, struct inputctx* ictx, unsigned candidate,
570573
}
571574
return 0;
572575
}
576+
assert(e->trie);
573577
if((a->state = e->trie[candidate]) == 0){
574578
if(esctrie_idx(a, e) == a->escapes){
575579
memset(ni, 0, sizeof(*ni));

src/third-party/notcurses/src/lib/in.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,13 +2309,14 @@ process_escape(inputctx* ictx, const unsigned char* buf, int buflen){
23092309
ncinput ni = {0};
23102310
logdebug("walk_auto %u (%c)", candidate, isprint(candidate) ? candidate : ' ');
23112311
int w = walk_automaton(&ictx->amata, ictx, candidate, &ni);
2312-
logdebug("walk result on %u (%c): %d %u", candidate,
2312+
logdebug("walk result on 0x%02x (%c): %d %u", candidate,
23132313
isprint(candidate) ? candidate : ' ', w, ictx->amata.state);
23142314
if(w > 0){
23152315
if(ni.id){
23162316
load_ncinput(ictx, &ni);
23172317
}
23182318
ictx->amata.used = 0;
2319+
ictx->amata.state = 0;
23192320
return used;
23202321
}else if(w < 0){
23212322
// all inspected characters are invalid; return full negative "used"
@@ -2338,7 +2339,7 @@ process_escape(inputctx* ictx, const unsigned char* buf, int buflen){
23382339
static void
23392340
process_escapes(inputctx* ictx, unsigned char* buf, int* bufused){
23402341
int offset = 0;
2341-
while(*bufused){
2342+
while(*bufused > 0){
23422343
int consumed = process_escape(ictx, buf + offset, *bufused);
23432344
// negative |consumed| means either that we're not sure whether it's an
23442345
// escape, or it definitely is not.
@@ -2370,7 +2371,7 @@ process_escapes(inputctx* ictx, unsigned char* buf, int* bufused){
23702371
}
23712372
// move any leftovers to the front; only happens if we fill output queue,
23722373
// or ran out of input data mid-escape
2373-
if(*bufused){
2374+
if(*bufused > 0){
23742375
ictx->amata.matchstart = buf;
23752376
memmove(buf, buf + offset, *bufused);
23762377
}
@@ -2449,7 +2450,7 @@ process_bulk(inputctx* ictx, unsigned char* buf, int* bufused){
24492450
offset += consumed;
24502451
}
24512452
// move any leftovers to the front
2452-
if(*bufused){
2453+
if(*bufused > 0){
24532454
memmove(buf, buf + offset, *bufused);
24542455
}
24552456
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
 Thu Nov 03 09:20:00 2005  1 normal 2 errors 0 warnings  0 marks
2-
 Thu Nov 03 09:45:00 2005  1 normal 0 errors 0 warnings 0 marks
3-
 Fri Feb 03 09:20:00 2006  0 normal 1 errors 0 warnings 0 marks
4-
 Wed Jan 03 09:20:00 2007  1 normal 0 errors 0 warnings 0 marks
1+
 Thu Nov 03 09:20:00 2005  1 normal 2 errors 0 warnings 0 marks
2+
 Thu Nov 03 09:45:00 2005  1 normal 0 errors 0 warnings 0 marks
3+
 Fri Feb 03 09:20:00 2006  0 normal 1 errors 0 warnings 0 marks
4+
 Wed Jan 03 09:20:00 2007  1 normal 0 errors 0 warnings 0 marks
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
 Sat Nov 03 08:00:00 2007 1 normal 0 errors 0 warnings  0 marks
1+
 Sat Nov 03 08:00:00 2007 1 normal 0 errors 0 warnings 0 marks
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
 Sat Nov 03 09:20:00 2007 1 normal 2 errors 0 warnings  1 marks
2-
 Sat Nov 03 09:45:00 2007 1 normal 0 errors 0 warnings 0 marks
1+
 Sat Nov 03 09:20:00 2007 1 normal 2 errors 0 warnings 1 marks
2+
 Sat Nov 03 09:45:00 2007 1 normal 0 errors 0 warnings 0 marks
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
 Sat Nov 03 00:00:00 2007 2 normal 2 errors 0 warnings  0 marks
1+
 Sat Nov 03 00:00:00 2007 2 normal  2 errors 0 warnings 0 marks
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
 Sat Nov 03 08:00:00 2007 2 normal 2 errors 0 warnings  0 marks
1+
 Sat Nov 03 08:00:00 2007 2 normal  2 errors 0 warnings 0 marks

0 commit comments

Comments
 (0)