SVN commit 634407 by porten: parse null characters (backported from trunk) M +4 -0 ChangeLog M +17 -10 lexer.cpp M +3 -2 lexer.h --- branches/KDE/3.5/kdelibs/kjs/ChangeLog #634406:634407 @@ -1,3 +1,7 @@ +2007-02-17 Harri Porten + + * lexer.cpp: parse code with null characters in them + 2007-02-10 Harri Porten * lexer.cpp: support named function expressions --- branches/KDE/3.5/kdelibs/kjs/lexer.cpp #634406:634407 @@ -120,10 +120,10 @@ #endif // read first characters - current = (length > 0) ? code[0].uc : 0; - next1 = (length > 1) ? code[1].uc : 0; - next2 = (length > 2) ? code[2].uc : 0; - next3 = (length > 3) ? code[3].uc : 0; + current = (length > 0) ? code[0].uc : -1; + next1 = (length > 1) ? code[1].uc : -1; + next2 = (length > 2) ? code[2].uc : -1; + next3 = (length > 3) ? code[3].uc : -1; } void Lexer::shift(unsigned int p) @@ -133,7 +133,7 @@ current = next1; next1 = next2; next2 = next3; - next3 = (pos + 3 < length) ? code[pos+3].uc : 0; + next3 = (pos + 3 < length) ? code[pos+3].uc : -1; } } @@ -201,7 +201,7 @@ } else if (current == '/' && next1 == '*') { shift(1); state = InMultiLineComment; - } else if (current == 0) { + } else if (current == -1) { if (!terminator && !delimited) { // automatic semicolon insertion if program incomplete token = ';'; @@ -258,7 +258,7 @@ if (current == stringType) { shift(1); setDone(String); - } else if (current == 0 || isLineTerminator) { + } else if (current == -1 || isLineTerminator) { setDone(Bad); } else if (current == '\\') { state = InEscapeSequence; @@ -333,12 +333,12 @@ setDone(Other); } else state = Start; - } else if (current == 0) { + } else if (current == -1) { setDone(Eof); } break; case InMultiLineComment: - if (current == 0) { + if (current == -1) { setDone(Bad); } else if (isLineTerminator) { nextLine(); @@ -817,6 +817,13 @@ buffer8[pos8++] = (char) c; } +void Lexer::record16(int c) +{ + assert(c >= 0); + //assert(c <= USHRT_MAX); + record16(UChar(static_cast(c))); +} + void Lexer::record16(UChar c) { // enlarge buffer if full @@ -838,7 +845,7 @@ bool inBrackets = false; while (1) { - if (current == '\r' || current == '\n' || current == 0) + if (current == '\r' || current == '\n' || current == -1) return false; else if (current != '/' || lastWasEscape == true || inBrackets == true) { --- branches/KDE/3.5/kdelibs/kjs/lexer.h #634406:634407 @@ -129,6 +129,7 @@ private: void record8(unsigned short c); + void record16(int c); void record16(UChar c); KJS::Identifier *makeIdentifier(UChar *buffer, unsigned int pos); @@ -141,8 +142,8 @@ int bol; // begin of line #endif - // current and following unicode characters - unsigned short current, next1, next2, next3; + // current and following unicode characters (int to allow for -1 for end-of-file marker) + int current, next1, next2, next3; UString **strings; unsigned int numStrings;