82. SensorFrame Deep Copy Fix

A data-processing pipeline has reported that sensor readings become corrupted after frame duplication. The issue appears only when SensorFrame objects are copied. A minimal reproduction has been provided.

Your task is to investigate why the corruption occurs, identify the underlying ownership flaw, and update the class implementation so copied frames operate independently.

After your fix:

  • Modifying one frame must not affect another
  • Frames must maintain isolated storage
  • Behavior must be deterministic and free of corruption

Program Flow:

  1. Read 8 bytes
  2. Construct frame A
  3. Create frame B as a copy of A
  4. Modify B at index 3
  5. Print A
  6. Print B

Before fixing the class:

A and B both reflect the modification.

After fixing the class:

Only B reflects the modification; A must remain unchanged.

 

Example Input:

1 2 3 4 5 6 7 8

Example Output (After Fix):

1 2 3 4 5 6 7 8
1 2 3 99 5 6 7 8

 

Constraints:

  • The class must be corrected to ensure safe and independent behavior when copied
  • Memory management must be robust
  • Output formatting must match exactly

 

 

 

Loading...

Input

1 2 3 4 5 6 7 8

Expected Output

1 2 3 4 5 6 7 8 1 2 3 99 5 6 7 8