fix(advanced_table): Use std.mem.swap for Row sorting + doc warnings

- Replace manual temp variable swap with std.mem.swap (more explicit)
- Add documentation warning about pointer invalidation after sort/setRows
- Row contains StringHashMap with internal pointers - swap is safe but
  pointers obtained via getRow() are invalidated after mutations

Based on INFORME_AUDITORIA_PROFUNDA_20251225.md §1.2
This commit is contained in:
reugenio 2025-12-25 23:03:54 +01:00
parent 1c284ed0f6
commit 7f8870d890
2 changed files with 9 additions and 4 deletions

View file

@ -1243,10 +1243,11 @@ fn sortRows(
};
if (should_swap) {
// Swap rows
const temp = table_state.rows.items[i];
table_state.rows.items[i] = table_state.rows.items[i + 1];
table_state.rows.items[i + 1] = temp;
// Swap rows usando std.mem.swap (seguro para structs con punteros internos)
// NOTA: Row contiene StringHashMap que tiene punteros a buckets.
// El swap mueve el struct completo, no clona los datos.
// Los punteros obtenidos via getRow() se invalidan tras sort.
std.mem.swap(Row, &table_state.rows.items[i], &table_state.rows.items[i + 1]);
// Swap state map entries
swapRowStates(table_state, i, i + 1);

View file

@ -231,12 +231,16 @@ pub const AdvancedTableState = struct {
}
/// Get row by index
/// ADVERTENCIA: El puntero retornado se invalida tras sortRows() o setRows().
/// No guardar el puntero entre frames - obtenerlo de nuevo cuando sea necesario.
pub fn getRow(self: *AdvancedTableState, index: usize) ?*Row {
if (index >= self.rows.items.len) return null;
return &self.rows.items[index];
}
/// Get row by index (const)
/// ADVERTENCIA: El puntero retornado se invalida tras sortRows() o setRows().
/// No guardar el puntero entre frames - obtenerlo de nuevo cuando sea necesario.
pub fn getRowConst(self: *const AdvancedTableState, index: usize) ?*const Row {
if (index >= self.rows.items.len) return null;
return &self.rows.items[index];