Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
    • Handle and Copy Puzzles
      • Shallow Copy in Nested Payload
      • Queue of Handle Cells Still Aliases
      • Analysis Port Lifetime Reuse
      • Null Handle During Partial Deep Copy
      • Handle Equality vs Content Equality
      • Clone Without Overridden do_copy
    • Virtual Method Puzzles
    • Parameterized Class Puzzles
    • Factory Override Puzzles
    • OOP & Testbench Puzzles: Tricky Q&A
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Handle and Copy Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Handle and Copy Puzzles
  5. Null Handle During Partial Deep Copy
On this page

    VLSI DV Interview PuzzlesAll levels

    Null Handle During Partial Deep Copy

    This `do_copy` tries to deep-copy nested policy object, but simulation crashes with null-handle access. Identify root cause and fix.

    Puzzle

    Difficulty: Medium · Puzzle 4 of 6 · Topic: Handle and Copy Puzzles

    This `do_copy` tries to deep-copy nested policy object, but simulation crashes with null-handle access. Identify root cause and fix.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    class qos extends uvm_object;
      `uvm_object_utils(qos)
      int prio;
      function new(string name="qos"); super.new(name); endfunction
    endclass
    
    class pkt extends uvm_sequence_item;
      `uvm_object_utils(pkt)
      qos policy;
      function new(string name="pkt");
        super.new(name);
      endfunction
      function void do_copy(uvm_object rhs);
        pkt r;
        if (!$cast(r, rhs)) return;
        policy.copy(r.policy);
      endfunction
    endclass

    Hint

    Before calling `policy.copy(...)`, what must be true about destination handle allocation?

    Step-by-step solution

    Diagram
    1) `policy` is never constructed in `new`, so destination handle remains null.
    2) `policy.copy(r.policy)` dereferences null and triggers runtime fatal/null-handle error.
    3) Allocate destination before copy (`if (policy == null) policy = qos::type_id::create(...)`).
    4) Also guard source null case and set destination null accordingly.
    5) The override also never calls `super.do_copy(rhs)`, so base-class state is skipped as well.

    Answer

    Answer: Crash occurs because `policy` is null in destination (never built in `new`); `policy.copy(r.policy)` dereferences an unallocated nested handle. Fix: call `super.do_copy(rhs)`, then if `r.policy == null` set `policy = null`, else allocate `policy` if needed and `policy.copy(r.policy)`.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. A hand-written model (not the UVM library): the destination policy handle is null until something allocates it, so the guarded copy allocates first.

    Why candidates get it wrong

    `policy.copy(...)` copies into an existing object; it never allocates the destination. The null is on the left of the dot, not the right.

    Interviewer follow-up

    How would you implement symmetric null-handling so copy preserves null vs non-null state exactly? Model answer: `if (r.policy == null) policy = null; else begin if (policy == null) policy = qos::type_id::create("policy"); policy.copy(r.policy); end`. Both null and non-null cases then leave source and destination in the same state, and the destination object is reused when it already exists.

    Say it out loud

    It crashes with a null handle error, because the policy handle is never built in the constructor, so copying into it dereferences null. The override also never calls super do_copy, so base-class state is skipped too. The trap is only noticing the null and missing the missing super call. I would call super do_copy first, set the policy to null if the source is null, otherwise allocate it if needed and copy, and then test both the null and non-null cases.

    Related topics

    • Shallow vs Deep Copy

    • Objects That Copy, Compare and Print

    • Back to Handle and Copy Puzzles

    • OOP & Testbench Puzzles section

    Previous

    39 / 293

    Next: Handle Equality vs Content Equality

    Up next

    Up nextHandle Equality vs Content Equality

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Shallow Copy in Nested Payload
    • Queue of Handle Cells Still Aliases
    • Clone Without Overridden do_copy