tinycodinglm / misc /misc-0001.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame
6.61 kB
human-crafted trace
System You're a helpful assistant.

You're a helpful assistant.

User

why do most of the LLMs misses most of the errors when reviewing a codebase?

Assistant

Because most LLMs are much better at explaining code than systematically verifying code.

Code review is fundamentally different from code generation. Several limitations contribute to this.

1. They review code probabilistically, not exhaustively

An LLM doesn't inherently execute every possible path through a program.

It predicts likely problems based on patterns it has learned.

For example:

markdown
int calculate(int x)
{
    if (x > 0)
        return x * 2;

    return x * -2;
}

A model might say this is correct because it looks reasonable.

But if x == INT_MIN, negating it causes signed integer overflow, which is undefined behavior in C++.

The problem is that the model often recognizes familiar patterns without checking every boundary condition.

2. Context limitations

Large codebases contain dependencies across:

  • Multiple translation units.
  • Header declarations and implementations.
  • Build configurations.
  • Platform-specific implementations.
  • Conditional compilation.
  • Runtime initialization and destruction.
  • External libraries.

Even when a model supports a huge context window, that doesn't mean it can reliably reason about every relationship inside it.

Context capacity is not reasoning capacity.

3. They struggle with data flow and control flow

Consider:

markdown
void process(Request* request)
{
    validate(request);

    if (request->flags & FLAG_ADMIN)
        execute_privileged(request);
}

A superficial review might conclude that the request is validated.

But what if validate() only checks whether the pointer is non-null?

Or what if it returns an error code that the caller ignores?

Understanding the actual behavior requires following the implementation, not trusting function names.

4. They miss interactions between individually correct components

This is particularly problematic.

Imagine:

  • Function A correctly allocates a buffer.
  • Function B correctly calculates its size.
  • Function C correctly frees it.

Individually, everything looks fine.

But if B calculates the size using a different encoding assumption than A, the combined implementation might overflow the buffer.

LLMs frequently review functions in isolation instead of constructing a complete model of their interactions.

5. They suffer from confirmation bias

Once a model decides that a function is probably correct, subsequent reasoning tends to reinforce that conclusion.

They also tend to:

  • Trust comments and function names.
  • Assume conventional behavior.
  • Overlook unusual integer ranges.
  • Ignore unlikely execution paths.
  • Accept existing architectural assumptions.
  • Prefer reporting obvious issues over investigating subtle ones.

This makes them particularly bad at finding bugs that contradict their initial interpretation.

6. They don't naturally perform adversarial testing

A proper reviewer should actively attempt to break the implementation.

For example:

Review dimension What to investigate
Memory safety UAF, OOB, double-free, leaks
Integer safety Overflow, underflow, truncation
Concurrency Races, deadlocks, ordering
Logic Incorrect conditions, unreachable branches
Error handling Ignored errors, partial initialization
API contracts Invalid assumptions, ownership violations
Portability ABI, alignment, endianness
Security Trust boundaries, validation bypasses

LLMs often produce a generic review rather than systematically examining each category.

7. They can mistake plausible explanations for evidence

This is arguably the most dangerous limitation.

A model might report:

The buffer is properly bounds-checked before access.

But did it actually verify that the bound corresponds to the allocated buffer size?

Did it check integer overflow in the calculation?

Did it inspect every access?

A convincing explanation is not proof.

What actually works better?

For serious codebase reviews, I would use a combination:

Tool Primary purpose
Compiler warnings Type and compilation issues
Static analyzers Detect suspicious code paths
Sanitizers Detect runtime memory/UB issues
Fuzzing Explore unexpected inputs
Symbolic execution Explore path conditions
LLM Understand architecture and investigate suspicious behavior
Human review Validate assumptions and findings

A better LLM review methodology

Instead of asking:

Review this codebase and find bugs.

Break the task into stages:

  1. Architecture discovery: Identify components, dependencies, ownership and data flow.
  2. Inventory: Enumerate public functions, entry points and critical state.
  3. Contract extraction: Determine preconditions, postconditions and invariants.
  4. Systematic inspection: Review every function against explicit bug categories.
  5. Cross-component analysis: Trace values across function boundaries.
  6. Adversarial verification: Attempt to construct concrete failing inputs.
  7. Evidence collection: Require file locations, execution paths and explanations for every finding.

Most importantly, maintain a checklist of inspected functions. Otherwise, the model can quietly skip half the codebase and still deliver a beautifully formatted report.

The fundamental problem: LLMs are optimized to produce plausible answers, whereas code auditing requires demonstrating that specific properties hold across an enormous number of possible execution paths.

Those are very different objectives.