{"record":{"id":"3d6418154bbee3c2","repo":"krahets/hello-algo","slug":"error-3d6418","errorCode":null,"errorMessage":"インデックスが範囲外です","messagePattern":"インデックスが範囲外です","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ja/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/ja/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 (Japanese localization). It fires when the supplied index is outside [0, items.len). Note: because index is usize (unsigned), the `index < 0` half of the guard is dead code — only the `index >= self.items.len` check can ever trigger. @panic aborts the process and is not catchable.","triggerScenarios":"Calling list.get(idx) with idx >= current element count, or with idx on a freshly-cleared list.","commonSituations":"Off-by-one loops (using <= len instead of < len); stale cached length after removes; reading from a list that was shrunk; negative-index expectations ported from Python.","solutions":["Bounds-check before access: if (idx >= list.getSize()) return early or handle.","Drive loops with list.getSize() captured once, iterating idx < size.","Re-fetch the size after any insert/remove mutation before re-indexing.","Remove the dead `index < 0` branch — it misleads readers about usize semantics."],"exampleFix":"// before\nvar v = list.get(idx); // @panics when idx >= len\n\n// after\nif (idx >= list.getSize()) {\n    return; // handle out-of-range\n}\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":["index is usize — a negative value can never occur; do not write code assuming index < 0 is possible.","Re-fetch getSize() after any insert/remove before re-indexing.","Iterate with idx < getSize(), never idx <= getSize()."],"tags":["zig","array-list","panic","bounds-check","data-structure","i18n-ja","dead-code"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}