Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the validity of all mbc created #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/org/joni/OptMapInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.jcodings.CaseFoldCodeItem;
import org.jcodings.Encoding;
import org.joni.exception.ErrorMessages;
import org.joni.exception.ValueException;

final class OptMapInfo {

Expand Down Expand Up @@ -61,7 +63,10 @@ void addCharAmb(byte[]bytes, int p, int end, Encoding enc, int caseFoldFlag) {

byte[] buf = new byte[Config.ENC_CODE_TO_MBC_MAXLEN];
for (int i=0; i<items.length; i++) {
enc.codeToMbc(items[i].code[0], buf, 0);
int len = enc.codeToMbc(items[i].code[0], buf, 0);
if (enc.length(buf, 0, len) < 0) {
throw new ValueException(ErrorMessages.ERR_INVALID_UNICODE);
}
addChar(buf[0], enc);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/org/joni/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ private Node parseExp(TokenType term) {
case CODE_POINT:
byte[]buf = new byte[Config.ENC_CODE_TO_MBC_MAXLEN];
int num = enc.codeToMbc(token.getCode(), buf, 0);
if (enc.length(buf, 0, num) < 0) {
newValueException(ERR_INVALID_UNICODE);
}
// #ifdef NUMBERED_CHAR_IS_NOT_CASE_AMBIG ... // setRaw() #else
node = new StringNode(buf, 0, num);
break;
Expand Down
6 changes: 6 additions & 0 deletions src/org/joni/ast/StringNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.jcodings.Encoding;
import org.joni.Config;
import org.joni.constants.StringType;
import org.joni.exception.ErrorMessages;
import org.joni.exception.ValueException;

public final class StringNode extends Node implements StringType {

Expand Down Expand Up @@ -154,7 +156,11 @@ public void cat(byte c) {

public void catCode(int code, Encoding enc) {
ensure(Config.ENC_CODE_TO_MBC_MAXLEN);
int oldEnd = end;
end += enc.codeToMbc(code, bytes, end);
if (enc.length(bytes, oldEnd, end) < 0) {
throw new ValueException(ErrorMessages.ERR_INVALID_UNICODE);
}
}

public void clear() {
Expand Down
1 change: 1 addition & 0 deletions src/org/joni/exception/ErrorMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ public interface ErrorMessages extends org.jcodings.exception.ErrorMessages {
final String ERR_INVALID_COMBINATION_OF_OPTIONS = "invalid combination of options";
final String ERR_OVER_THREAD_PASS_LIMIT_COUNT = "over thread pass limit count";
final String ERR_TOO_BIG_SB_CHAR_VALUE = "too big singlebyte char value";
final String ERR_INVALID_UNICODE = "invalid unicode";

}