{"record":{"id":"63dd9ca74b59058f","repo":"gfx-rs/wgpu","slug":"mid-len","errorCode":null,"errorMessage":"mid > len","messagePattern":"mid > len","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-types/src/write_only.rs","lineNumber":481,"sourceCode":"        (array_slice, remainder)\n    }\n\n    /// Divides one write-only slice reference into two at an index.\n    ///\n    /// The first will contain all indices from `[0, mid)` (excluding\n    /// the index `mid` itself) and the second will contain all\n    /// indices from `[mid, len)` (excluding the index `len` itself).\n    ///\n    /// # Panics\n    ///\n    /// Panics if `mid > len`.\n    #[inline]\n    #[must_use]\n    #[track_caller]\n    pub fn split_at(self, mid: usize) -> (WriteOnly<'a, [T]>, WriteOnly<'a, [T]>) {\n        match self.split_at_checked(mid) {\n            Ok(slices) => slices,\n            Err(_) => panic!(\"mid > len\"),\n        }\n    }\n\n    /// Divides one write-only slice reference into two at an index, returning [`Err`] if the\n    /// slice is too short.\n    ///\n    /// If `mid ≤ len`, returns a pair of slices where the first will contain all\n    /// indices from `[0, mid)` (excluding the index `mid` itself) and the\n    /// second will contain all indices from `[mid, len)` (excluding the index\n    /// `len` itself).\n    ///\n    /// Otherwise, if `mid > len`, returns [`Err`] with the original slice.\n    #[inline]\n    pub const fn split_at_checked(self, mid: usize) -> Result<(Self, Self), Self> {\n        if mid <= self.len() {\n            let Self { ptr, _phantom: _ } = self;\n            let element_ptr = ptr.cast::<T>();\n            Ok(unsafe {","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-types/src/write_only.rs#L463-L499","documentation":"WriteOnly<[T]>::split_at panics when mid is greater than the slice's length. It is the infallible variant of split_at_checked and is also reachable indirectly through into_chunks, which calls split_at at each chunk boundary.","triggerScenarios":"Calling slice.split_at(mid) with mid > slice.len(), or calling into_chunks with a chunk size that does not divide the slice length so the final split_at goes past the end.","commonSituations":"Dividing a mapped buffer slice into fixed-size chunks (e.g. uniforms of 256 bytes) without handling the remainder, or computing mid from a wrong constant/stride.","solutions":["Ensure mid <= slice.len(): clamp with mid.min(slice.len()) or check first.","Use split_at_checked and handle the Err case instead of split_at.","For into_chunks, size the buffer to be an exact multiple of the chunk size, or use chunks_exact-style logic for the tail."],"exampleFix":"// before\nlet (a, b) = slice.split_at(chunk_size); // chunk_size may exceed len\n// after\nlet (a, b) = match slice.split_at_checked(chunk_size) {\n    Ok(pair) => pair,\n    Err(_) => (slice, /* empty tail */ slice.split_at(slice.len()).1),\n};","handlingStrategy":"validation","validationCode":"if mid > slice.len() {\n    return Err(format!(\"split_at mid {mid} exceeds len {}\", slice.len()));\n}\nlet (a, b) = slice.split_at(mid);","typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| slice.split_at(mid)));","preventionTips":["Prefer split_at_checked and handle Err explicitly.","When using into_chunks, ensure the buffer length is a multiple of the chunk size or handle the remainder chunk.","Clamp mid with slice.len() before splitting."],"tags":["panic","rust","buffer-mapping","out-of-range"],"backgroundTag":"slice-index-out-of-range","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}