only: improved overflow checking
This commit is contained in:
parent
41df2c32d5
commit
79af8c6411
|
@ -159,7 +159,7 @@ public class EnumIniField extends IniField {
|
|||
|
||||
public static class EnumKeyValueMap {
|
||||
private static final String STARTS_WITH_NUMBERS_OPTIONAL_SPACES_AND_EQUALS = "^\\d+\\s*=.*";
|
||||
private static Pattern IS_KEY_VALUE_SYNTAX = Pattern.compile(STARTS_WITH_NUMBERS_OPTIONAL_SPACES_AND_EQUALS);
|
||||
private static final Pattern IS_KEY_VALUE_SYNTAX = Pattern.compile(STARTS_WITH_NUMBERS_OPTIONAL_SPACES_AND_EQUALS);
|
||||
|
||||
private final Map<Integer, String> keyValues;
|
||||
|
||||
|
@ -198,7 +198,7 @@ public class EnumIniField extends IniField {
|
|||
return new EnumKeyValueMap(keyValues);
|
||||
}
|
||||
|
||||
private static boolean isKeyValueSyntax(String rawText) {
|
||||
public static boolean isKeyValueSyntax(String rawText) {
|
||||
String interestingPart = getEnumValuesSection(rawText);
|
||||
return IS_KEY_VALUE_SYNTAX.matcher(interestingPart).matches();
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ public class EnumIniField extends IniField {
|
|||
}
|
||||
|
||||
@NotNull
|
||||
private static String getEnumValuesSection(String rawText) {
|
||||
public static String getEnumValuesSection(String rawText) {
|
||||
int interestingIndex = EnumIniField.ordinalIndexOf(rawText, ",", 4);
|
||||
// yes that could have been done with a regex as well
|
||||
return rawText.substring(interestingIndex + /*skipping comma*/1).trim();
|
||||
|
|
|
@ -167,13 +167,12 @@ public class ReaderStateImpl implements ReaderState {
|
|||
tsCustomSize.put(name, size);
|
||||
|
||||
RawIniFile.Line rawLine = new RawIniFile.Line(tunerStudioLine);
|
||||
//boolean isKeyValueForm = tunerStudioLine.contains("=\"");
|
||||
if (rawLine.getTokens()[0].equals("bits")) {
|
||||
EnumIniField.ParseBitRange bitRange = new EnumIniField.ParseBitRange().invoke(rawLine.getTokens()[3]);
|
||||
int totalCount = 1 << (bitRange.getBitSize0() + 1);
|
||||
List<String> enums = Arrays.asList(rawLine.getTokens()).subList(4, rawLine.getTokens().length);
|
||||
// at the moment we read 0=NONE as two tokens, thus enums.size() is divided by two
|
||||
if (enums.size() / 2 > totalCount)
|
||||
int enumCount = EnumIniField.EnumKeyValueMap.isKeyValueSyntax(EnumIniField.getEnumValuesSection(tunerStudioLine)) ? enums.size() / 2 : enums.size();
|
||||
if (enumCount > totalCount)
|
||||
throw new IllegalStateException(name + ": Too many options in " + tunerStudioLine + " capacity=" + totalCount + "/size=" + enums.size());
|
||||
/*
|
||||
this does not work right now since smt32 and kinetis enum sizes could be different but same .txt file
|
||||
|
|
Loading…
Reference in New Issue