{"record":{"id":"385311f2946721ff","repo":"NationalSecurityAgency/ghidra","slug":"is-not-a-constant","errorCode":null,"errorMessage":"{} is not a constant","messagePattern":"(.+?) is not a constant","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/ghidra/pcode/eval/AbstractVarnodeEvaluator.java","lineNumber":364,"sourceCode":"\t * @param program the program defining the static context\n\t * @param op the op whose output to evaluate\n\t * @param already a cache of already-evaluated varnodes and their values\n\t * @return the output value\n\t */\n\tprotected abstract T evaluatePtrSub(Program program, PcodeOp op, Map<Varnode, T> already);\n\n\t/**\n\t * Assert that a varnode is constant and get its value as an integer.\n\t * \n\t * <p>\n\t * Here \"constant\" means a literal or immediate value. It does not read from the state.\n\t * \n\t * @param vn the varnode\n\t * @return the value\n\t */\n\tprotected int getIntConst(Varnode vn) {\n\t\tif (!vn.isConstant()) {\n\t\t\tthrow new IllegalArgumentException(vn + \" is not a constant\");\n\t\t}\n\t\treturn (int) vn.getAddress().getOffset();\n\t}\n\n\t/**\n\t * Evaluate a {@link PcodeOp#LOAD} op\n\t * \n\t * @param program the program defining the static context\n\t * @param op the op whose output to evaluate\n\t * @param already a cache of already-evaluated varnodes and their values\n\t * @return the output value\n\t */\n\tprotected abstract T evaluateLoad(Program program, PcodeOp op, Map<Varnode, T> already);\n\n\t@Override\n\tpublic T evaluateOp(Program program, PcodeOp op) {\n\t\treturn evaluateOp(program, op, new HashMap<>());\n\t}","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/ghidra/pcode/eval/AbstractVarnodeEvaluator.java#L346-L382","documentation":"Thrown (unchecked IllegalArgumentException) by getIntConst(Varnode) when the passed varnode is not constant (vn.isConstant() is false). getIntConst reads a literal/immediate value directly from the varnode offset; a non-constant varnode (register/memory/unique) has no such immediate, so the precondition is violated.","triggerScenarios":"Calling getIntConst on a varnode that is a register, memory reference, unique, or any computed value rather than an immediate operand. Typically inside an evaluateOp override that fetches an input operand expecting it to be immediate when it is not.","commonSituations":"Mis-assuming a p-code op's input is always immediate (e.g. for INT_ADD, CBUILD, STORE size input); evaluating p-code whose operands were constant-folded away or are dynamic; an op where the immediate is the second operand but code reads the first.","solutions":["Guard with vn.isConstant() before calling getIntConst, and handle the non-constant case (e.g. evaluate it via evaluateVarnode).","Double-check you are reading the correct operand index for the immediate.","For ops with conditionally-constant operands, branch on isConstant rather than assuming it."],"exampleFix":"// before\nint n = evaluator.getIntConst(op.getInput(1)); // throws if input is dynamic\n\n// after: check before reading\nVarnode in = op.getInput(1);\nint n = in.isConstant() ? evaluator.getIntConst(in) : (int) evaluator.evaluateVarnode(program, in, cache).getValue();","handlingStrategy":"validation","validationCode":"// Check constancy before reading as int constant\nif (!vn.isConstant()) {\n    // do not call getIntConst; evaluate the value instead\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always guard getIntConst with vn.isConstant().","Verify you read the correct (immediate) operand index for the op.","Branch on isConstant for ops with conditionally-immediate operands."],"tags":["pcode","emulation","constant","varnode","illegal-argument","unchecked-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}