File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1
1
#include <stdlib.h>
2
2
#include <stdio.h>
3
3
#include <string.h>
4
+ #include <stdint.h>
4
5
#include <assert.h>
5
6
6
7
#include "config.h"
@@ -81,15 +82,17 @@ static int longest_backtick_sequence(const char *code) {
81
82
}
82
83
83
84
static int shortest_unused_backtick_sequence (const char * code ) {
84
- int32_t used = 1 ;
85
+ // note: if the shortest sequence is >= 32, this returns 32
86
+ // so as not to overflow the bit array.
87
+ uint32_t used = 1 ;
85
88
int current = 0 ;
86
89
size_t i = 0 ;
87
90
size_t code_len = strlen (code );
88
91
while (i <= code_len ) {
89
92
if (code [i ] == '`' ) {
90
93
current ++ ;
91
94
} else {
92
- if (current ) {
95
+ if (current > 0 && current < 32 ) {
93
96
used |= (1 << current );
94
97
}
95
98
current = 0 ;
@@ -98,7 +101,7 @@ static int shortest_unused_backtick_sequence(const char *code) {
98
101
}
99
102
// return number of first bit that is 0:
100
103
i = 0 ;
101
- while (used & 1 ) {
104
+ while (i < 32 && used & 1 ) {
102
105
used = used >> 1 ;
103
106
i ++ ;
104
107
}
You can’t perform that action at this time.
0 commit comments