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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • 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
  • Interview Prep: Puzzle Rounds5
  • 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

VLSI DV Interview Puzzles · All 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.

On this page

    Puzzle

    Difficulty: Hard · 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.

    Answer

    Answer: Crash occurs because `policy` is null in destination; deep-copy code dereferences an unallocated nested handle.

    Why candidates get it wrong

    Engineers remember to copy nested fields but forget destination object ownership/allocation lifecycle.

    Interviewer follow-up

    How would you implement symmetric null-handling so copy preserves null vs non-null state exactly?

    Related topics

    • Back to Handle and Copy Puzzles

    • OOP & Testbench Puzzles section

    Previous

    33 / 210

    Next: Handle Equality vs Content Equality

    Up next

    Up nextHandle Equality vs Content Equality

    Sign in to save progress

    Practice this lessonReport an error

    See also

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