StringIndexOutOfBoundsException on init of char arrays with '\0' in the content (C++) #214

Closed
dACymon opened this Issue Dec 14, 2011 · 1 comment

Projects

None yet

2 participants

@dACymon
dACymon commented Dec 14, 2011

With a line like

const char WINDOWS_ENDL_CH_CONST[3] = { 0x0d, 0x0a, '\0' };

a StringIndexOutOfBoundsException exception is raised.

Changing the '\0' to 0x00 fixes the problem temporary.

Log output:

Exception for null at line 0:java.util.concurrent.ExecutionException: java.lang.Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
java.util.concurrent.ExecutionException: java.lang.Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.ochafik.lang.jnaerator.JNAeratorParser.parseSlices(JNAeratorParser.java:177)
at com.ochafik.lang.jnaerator.JNAeratorParser.parse(JNAeratorParser.java:213)
at com.ochafik.lang.jnaerator.JNAerator.parseSources(JNAerator.java:1124)
at com.ochafik.lang.jnaerator.JNAerator.jnaerate(JNAerator.java:829)
at com.ochafik.lang.jnaerator.studio.JNAeratorStudio$14.run(JNAeratorStudio.java:607)
Caused by: java.lang.Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at com.ochafik.lang.jnaerator.JNAeratorParser$1.call(JNAeratorParser.java:147)
at com.ochafik.lang.jnaerator.JNAeratorParser$1.call(JNAeratorParser.java:136)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.charAt(Unknown Source)
at com.ochafik.lang.jnaerator.parser.Expression$Constant.parseNakedString(Expression.java:1273)
at com.ochafik.lang.jnaerator.parser.Expression$Constant.parseCharOrStringInteger(Expression.java:1217)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.constant(ObjCppParser.java:11739)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.baseExpression(ObjCppParser.java:8304)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.postfixExpr(ObjCppParser.java:10215)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.unaryExpr(ObjCppParser.java:9918)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.castExpr(ObjCppParser.java:9840)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.multExpr(ObjCppParser.java:8964)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.addExpr(ObjCppParser.java:8872)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.shiftExpr(ObjCppParser.java:9219)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.compareExpr(ObjCppParser.java:9646)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.equalExpr(ObjCppParser.java:9554)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.bitAndExpr(ObjCppParser.java:9138)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.xorExpr(ObjCppParser.java:9311)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.bitOrExpr(ObjCppParser.java:9057)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.logAndExpr(ObjCppParser.java:9473)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.logOrExpr(ObjCppParser.java:9392)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.inlineCondExpr(ObjCppParser.java:8788)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.assignmentExpr(ObjCppParser.java:8645)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.topLevelExpr(ObjCppParser.java:10451)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.topLevelExprList(ObjCppParser.java:10527)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.expression(ObjCppParser.java:10573)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.baseExpression(ObjCppParser.java:8387)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.postfixExpr(ObjCppParser.java:10215)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.unaryExpr(ObjCppParser.java:9918)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.castExpr(ObjCppParser.java:9840)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.multExpr(ObjCppParser.java:8964)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.addExpr(ObjCppParser.java:8872)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.shiftExpr(ObjCppParser.java:9219)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.compareExpr(ObjCppParser.java:9646)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.equalExpr(ObjCppParser.java:9554)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.bitAndExpr(ObjCppParser.java:9138)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.xorExpr(ObjCppParser.java:9311)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.bitOrExpr(ObjCppParser.java:9057)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.logAndExpr(ObjCppParser.java:9473)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.logOrExpr(ObjCppParser.java:9392)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.inlineCondExpr(ObjCppParser.java:8788)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.assignmentExpr(ObjCppParser.java:8645)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.topLevelExpr(ObjCppParser.java:10451)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.declaratorWithValue(ObjCppParser.java:6393)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.declaratorsList(ObjCppParser.java:6443)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.varDecl(ObjCppParser.java:6265)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.declaration(ObjCppParser.java:929)
at com.ochafik.lang.jnaerator.parser.ObjCppParser.sourceFile(ObjCppParser.java:551)
at com.ochafik.lang.jnaerator.JNAeratorParser$1.call(JNAeratorParser.java:142)
... 6 more

@ochafik ochafik added a commit that referenced this issue Dec 15, 2011
@ochafik ochafik JNAerator: fixed parsing of null char escape '\0' (issue #214), added…
… parsing of expression initializer blocks (v = { 1, 2, 3};), added preservation of original textual representation of constants
39112a5
@ochafik
Member
ochafik commented Dec 15, 2011

Hello dACymon,

Thank you very much for your report, I've committed a fix that's currently being deployed as a new snapshot 0.9.10-SNAPSHOT on the Maven repo.

Cheers

@ochafik ochafik closed this Dec 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment