Skip to main content

Practice ยท 1 of 1

Incident Repair: The Truncated Report

Incident report: averageOf returned garbage for a one-element report. The broken function divides by v.size() - 1 (a size_t), so an empty/one-element vector underflows the unsigned size. Repair it: return std::nullopt for an empty vector, and the correct mean otherwise.

Difficulty: advanced

Back to lesson: Practice: Practice: Sanitizer-Grade Repairs