{"record":{"id":"e9ec58408826b583","repo":"ben-manes/caffeine","slug":"wrong-ref-page-number-found-ld-n","errorCode":null,"errorMessage":"Wrong ref page number found: %ld.\\n","messagePattern":"Wrong ref page number found: %ld\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/lirs.c","lineNumber":181,"sourceCode":"\n      fscanf(trace_fp, \"%s\", ref_block_str);\n      if (strcmp(ref_block_str, \"*\")) {\n        ref_block = atoi(ref_block_str);\n      }\n      continue;\n    }\n\n    total_pg_refs++;\n    if (total_pg_refs % 10000 == 0) {\n      fprintf(stderr, \"%ld samples processed\\r\", total_pg_refs);\n    }\n    if (total_pg_refs > STAT_START_POINT) {\n      collect_stat = 1;\n      warm_pg_refs++;\n    }\n\n    if (ref_block > vm_size) {\n      fprintf(stderr, \"Wrong ref page number found: %ld.\\n\", ref_block);\n      return;\n    }\n\n    if (ref_block == last_ref_pg) {\n      fscanf(trace_fp, \"%s\", ref_block_str);\n      if (strcmp(ref_block_str, \"*\")) {\n        ref_block = atoi(ref_block_str);\n      }\n      continue;\n    }\n    else {\n      last_ref_pg = ref_block;\n    }\n\n    no_dup_refs++; /* ref counter excluding duplicate refs */\n\n    if (!page_tbl[ref_block].isResident) {  /* block miss */\n      if (collect_stat == 1) {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/ben-manes/caffeine/blob/9da6581ee366aa63c51e0dc96692d02f9c29ccff/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/lirs.c#L163-L199","documentation":"A data-validation error in lirs.c's trace reader: each trace line is parsed into ref_block, and if the referenced page number exceeds vm_size (the configured virtual memory size for the simulation), the tool prints 'Wrong ref page number found: %ld' and returns, skipping the sample. It exists because LIRS simulates a cache over a fixed address space of vm_size pages, and any reference beyond that space cannot be modeled — almost always a trace/format or vm_size-configuration mismatch.","triggerScenarios":"Replaying a trace whose maximum page/block number is larger than the vm_size passed to the tool (default virtual memory size too small); passing a trace in the wrong format so a non-numeric token (e.g. an opcode like 'R'/'W' or '*') is parsed as the block number; a trace with 1-based block numbers when the tool assumes a different base against a tight vm_size.","commonSituations":"Converting a multi-column trace (e.g. with access-type suffixes) through the LIRS converter without normalizing it first; forgetting to set the vm_size parameter to at least the trace's distinct-block count; mixing up the LIRS trace format expected by the simulator's lirs trace parser with the output of another generator.","solutions":["Set vm_size (virtual memory size) to a value >= the largest page number appearing in the trace, typically the distinct block count or max block id","Verify the trace format matches what lirs.c expects: a sequence of block numbers (with the tool's continuation marker '*'), preprocessed if needed","Sanitize the trace: strip headers, opcodes, or any non-numeric columns before feeding it in","Check the error's reported %ld value — if it looks like an ASCII/garbage number, the parser is reading the wrong column"],"exampleFix":"# before\n./lirs trace.dat 1000   # vm_size=1000 but trace has block ids up to 5000\n\n# after\n./lirs trace.dat 8192   # vm_size >= max block id in trace","handlingStrategy":"validation","validationCode":"# validate trace against vm_size before replay\nmax_id=$(awk '!/\\*/ {if ($1+0 > m) m = $1+0} END {print m}' trace.dat)\nvm_size=8192   # value you plan to pass\nif [ \"$max_id\" -ge \"$vm_size\" ]; then echo \"trace max id $max_id >= vm_size $vm_size\"; exit 1; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass vm_size >= the largest block id in the trace","Normalize traces to the plain numeric LIRS format ('*' continuation marker) before replay","Watch stderr for the reported wrong page number — a garbage value means wrong-column parsing","Pre-check distinct/max block ids with awk before converting"],"tags":["c","input-validation","trace-format","simulator","lirs"],"backgroundTag":null,"analyzedSha":"9da6581ee366aa63c51e0dc96692d02f9c29ccff","analyzedAt":"2026-08-14T14:45:28.147Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}