{"record":{"id":"ee4ef5149b12803a","repo":"krahets/hello-algo","slug":"error-ee4ef5","errorCode":null,"errorMessage":"индекс выходит за границы","messagePattern":"индекс выходит за границы","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/zig/chapter_array_and_linkedlist/my_list.zig","lineNumber":58,"sourceCode":"        const new_item_ptr = &self.items[self.items.len - 1];\n        new_item_ptr.* = item;\n    }\n\n    // Получить длину списка (текущее число элементов)\n    pub fn getSize(self: *Self) usize {\n        return self.items.len;\n    }\n\n    // Получить вместимость списка\n    pub fn getCapacity(self: *Self) usize {\n        return self.capacity;\n    }\n\n    // Доступ к элементу\n    pub fn get(self: *Self, index: usize) i32 {\n        // Если индекс выходит за границы, выбрасывается исключение; далее аналогично\n        if (index < 0 or index >= self.items.len) {\n            @panic(\"индекс выходит за границы\");\n        }\n        return self.items[index];\n    }\n\n    // Обновление элемента\n    pub fn set(self: *Self, index: usize, num: i32) void {\n        // Если индекс выходит за границы, выбрасывается исключение; далее аналогично\n        if (index < 0 or index >= self.items.len) {\n            @panic(\"индекс выходит за границы\");\n        }\n        self.items[index] = num;\n    }\n\n    // Вставка элемента в середину\n    pub fn insert(self: *Self, index: usize, item: i32) !void {\n        if (index < 0 or index >= self.items.len) {\n            @panic(\"индекс выходит за границы\");\n        }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/zig/chapter_array_and_linkedlist/my_list.zig#L40-L76","documentation":"This panic is raised by get() in a hand-written dynamic array / MyList (Russian localization). It fires when index >= items.len. Because index is usize (unsigned), the `index < 0` branch is dead code — only `index >= self.items.len` can trigger. @panic aborts the process and is not catchable.","triggerScenarios":"Calling list.get(idx) with idx at or beyond the current element count; reading from a freshly-cleared or never-populated list.","commonSituations":"Off-by-one read loops; stale cached size after removals; capacity-vs-length confusion; negative-index expectations ported from Python.","solutions":["Bounds-check before access: if (idx >= list.getSize()) handle and return.","Iterate with idx < getSize() captured once per loop.","Re-fetch size after any mutation before re-indexing.","Drop the misleading `index < 0` branch for usize clarity."],"exampleFix":"// before\nvar v = list.get(idx); // @panics when idx >= len\n\n// after\nif (idx >= list.getSize()) return;\nvar v = list.get(idx);","handlingStrategy":"validation","validationCode":"// Bounds-check before indexed read\nif (idx < list.getSize()) {\n    var v = list.get(idx);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["usize means idx can never be negative — ignore the `index < 0` half of the guard.","Iterate with idx < getSize(); re-fetch after mutations.","Never use idx <= getSize() as a loop bound."],"tags":["zig","array-list","panic","bounds-check","data-structure","i18n-ru","dead-code"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}