#!/bin/bash # Script to add safety comments to unsafe blocks missing them # File: trading_engine/src/affinity.rs - Line 386 sed -i '386i\ // SAFETY: We use libc CPU_SET macros with a properly initialized cpu_set_t.\n // cpu_set_t is zeroed before use, and CPU_SET/CPU_ZERO are standard POSIX operations.\n // sched_setaffinity is called with valid parameters for the current thread (pid=0).' trading_engine/src/affinity.rs # File: trading_engine/src/affinity.rs - Line 467 (after previous additions, now ~470) sed -i '470i\ // SAFETY: Standard libc sched_setscheduler call with properly initialized sched_param.\n // We pass valid SCHED_FIFO policy and priority within acceptable range (1-99).' trading_engine/src/affinity.rs # File: trading_engine/src/affinity.rs - Line 492 (after previous additions, now ~498) sed -i '498i\ // SAFETY: mlockall is a standard libc call to lock memory pages.\n // Flags MCL_CURRENT and MCL_FUTURE are valid POSIX constants.' trading_engine/src/affinity.rs # File: trading_engine/src/affinity.rs - Line 519 (after previous additions, now ~528) sed -i '528i\ // SAFETY: sched_getaffinity reads CPU affinity into a properly initialized cpu_set_t.\n // The cpu_set_t is zeroed before use, ensuring safe initialization for the libc call.' trading_engine/src/affinity.rs echo "Added safety comments to trading_engine/src/affinity.rs"