19
19
#include < unistd.h>
20
20
#endif
21
21
22
- #include " helpers.hpp" // assume, QUOTEDSTRLEN
22
+ #include " helpers.hpp"
23
23
#include " util.hpp"
24
24
25
25
#include " asm/fixpoint.hpp"
@@ -500,27 +500,27 @@ BufferedContent::~BufferedContent() {
500
500
}
501
501
502
502
void BufferedContent::advance () {
503
- assume (offset < LEXER_BUF_SIZE );
503
+ assume (offset < ARRAY_SIZE (buf) );
504
504
offset++;
505
- if (offset == LEXER_BUF_SIZE )
505
+ if (offset == ARRAY_SIZE (buf) )
506
506
offset = 0 ; // Wrap around if necessary
507
507
assume (size > 0 );
508
508
size--;
509
509
}
510
510
511
511
void BufferedContent::refill () {
512
- size_t target = LEXER_BUF_SIZE - size; // Aim: making the buf full
512
+ size_t target = ARRAY_SIZE (buf) - size; // Aim: making the buf full
513
513
514
514
// Compute the index we'll start writing to
515
- size_t startIndex = (offset + size) % LEXER_BUF_SIZE ;
515
+ size_t startIndex = (offset + size) % ARRAY_SIZE (buf) ;
516
516
517
517
// If the range to fill passes over the buffer wrapping point, we need two reads
518
- if (startIndex + target > LEXER_BUF_SIZE ) {
519
- size_t nbExpectedChars = LEXER_BUF_SIZE - startIndex;
518
+ if (startIndex + target > ARRAY_SIZE (buf) ) {
519
+ size_t nbExpectedChars = ARRAY_SIZE (buf) - startIndex;
520
520
size_t nbReadChars = readMore (startIndex, nbExpectedChars);
521
521
522
522
startIndex += nbReadChars;
523
- if (startIndex == LEXER_BUF_SIZE )
523
+ if (startIndex == ARRAY_SIZE (buf) )
524
524
startIndex = 0 ;
525
525
526
526
// If the read was incomplete, don't perform a second read
@@ -534,7 +534,7 @@ void BufferedContent::refill() {
534
534
535
535
size_t BufferedContent::readMore (size_t startIndex, size_t nbChars) {
536
536
// This buffer overflow made me lose WEEKS of my life. Never again.
537
- assume (startIndex + nbChars <= LEXER_BUF_SIZE );
537
+ assume (startIndex + nbChars <= ARRAY_SIZE (buf) );
538
538
ssize_t nbReadChars = read (fd, &buf[startIndex], nbChars);
539
539
540
540
if (nbReadChars == -1 )
@@ -720,7 +720,7 @@ int LexerState::peekChar() {
720
720
auto &cbuf = content.get <BufferedContent>();
721
721
if (cbuf.size == 0 )
722
722
cbuf.refill ();
723
- assume (cbuf.offset < LEXER_BUF_SIZE );
723
+ assume (cbuf.offset < ARRAY_SIZE (cbuf. buf ) );
724
724
if (cbuf.size > 0 )
725
725
return static_cast <uint8_t >(cbuf.buf [cbuf.offset ]);
726
726
}
@@ -748,11 +748,11 @@ int LexerState::peekCharAhead() {
748
748
return static_cast <uint8_t >(view.span .ptr [view.offset + distance]);
749
749
} else {
750
750
auto &cbuf = content.get <BufferedContent>();
751
- assume (distance < LEXER_BUF_SIZE );
751
+ assume (distance < ARRAY_SIZE (cbuf. buf ) );
752
752
if (cbuf.size <= distance)
753
753
cbuf.refill ();
754
754
if (cbuf.size > distance)
755
- return static_cast <uint8_t >(cbuf.buf [(cbuf.offset + distance) % LEXER_BUF_SIZE ]);
755
+ return static_cast <uint8_t >(cbuf.buf [(cbuf.offset + distance) % ARRAY_SIZE (cbuf. buf ) ]);
756
756
}
757
757
758
758
// If there aren't enough chars, give up
0 commit comments