summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Lexer.cpp
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-13 09:15:00 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-13 18:52:58 +0200
commitd476144565c29a041b48fa21c734fd71d4508fe8 (patch)
treeefe460d4aae55764860f2af0a9ccf77a677da553 /Userland/Libraries/LibJS/Lexer.cpp
parent6ab48d612a0fbf7670accd07d3c48465d7bfa424 (diff)
downloadserenity-d476144565c29a041b48fa21c734fd71d4508fe8.zip
Userland: Allow building SerenityOS with -funsigned-char
Some of the code assumed that chars were always signed while that is not the case on ARM hosts. Also, some of the code tried to use EOF (-1) in a way similar to what fgetc() does, however instead of storing the characters in an int variable a char was used. While this seemed to work it also meant that character 0xFF would be incorrectly seen as an end-of-file. Careful reading of fgetc() reveals that fgetc() stores character data in an int where valid characters are in the range of 0-255 and the EOF value is explicitly outside of that range (usually -1).
Diffstat (limited to 'Userland/Libraries/LibJS/Lexer.cpp')
-rw-r--r--Userland/Libraries/LibJS/Lexer.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Lexer.cpp b/Userland/Libraries/LibJS/Lexer.cpp
index 386fdef2bf..32034fa831 100644
--- a/Userland/Libraries/LibJS/Lexer.cpp
+++ b/Userland/Libraries/LibJS/Lexer.cpp
@@ -139,9 +139,10 @@ void Lexer::consume()
auto did_reach_eof = [this] {
if (m_position != m_source.length())
return false;
+ m_eof = true;
+ m_current_char = '\0';
m_position++;
m_line_column++;
- m_current_char = EOF;
return true;
};
@@ -276,7 +277,7 @@ bool Lexer::match(char a, char b, char c, char d) const
bool Lexer::is_eof() const
{
- return m_current_char == EOF;
+ return m_eof;
}
bool Lexer::is_line_terminator() const
@@ -540,7 +541,7 @@ Token Lexer::next()
} else {
consume();
}
- } else if (m_current_char == EOF) {
+ } else if (m_eof) {
if (unterminated_comment) {
token_type = TokenType::Invalid;
token_message = "Unterminated multi-line comment";