{"record":{"id":"bf55926686a59413","repo":"dmtrKovalenko/fff","slug":"file-path-is-null-or-invalid-utf-8","errorCode":null,"errorMessage":"File path is null or invalid UTF-8","messagePattern":"File path is null or invalid UTF-8","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fff-c/src/lib.rs","lineNumber":1079,"sourceCode":"#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn fff_track_query(\n    fff_handle: *mut c_void,\n    query: *const c_char,\n    file_path: *const c_char,\n) -> *mut FffResult {\n    let inst = match unsafe { instance_ref(fff_handle) } {\n        Ok(i) => i,\n        Err(e) => return e,\n    };\n\n    let query_str = match unsafe { cstr_to_str(query) } {\n        Some(s) => s,\n        None => return FffResult::err(\"Query is null or invalid UTF-8\"),\n    };\n\n    let path_str = match unsafe { cstr_to_str(file_path) } {\n        Some(s) => s,\n        None => return FffResult::err(\"File path is null or invalid UTF-8\"),\n    };\n\n    let file_path = match fff::path_utils::canonicalize(path_str) {\n        Ok(p) => p,\n        Err(e) => return FffResult::err(&format!(\"Failed to canonicalize path: {}\", e)),\n    };\n\n    let project_path = {\n        let guard = match inst.picker.read() {\n            Ok(g) => g,\n            Err(_) => return FffResult::ok_int(0),\n        };\n        match guard.as_ref() {\n            Some(p) => p.base_path().to_path_buf(),\n            None => return FffResult::ok_int(0),\n        }\n    };\n","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/dmtrKovalenko/fff/blob/7f8537e70f0ea1210f9acbbfc4640141105cdc78/crates/fff-c/src/lib.rs#L1061-L1097","documentation":"fff_track_query validates the file_path argument with cstr_to_str; a NULL pointer or non-UTF-8 bytes yield this error. The library needs a real path string to canonicalize and record in the query history database.","triggerScenarios":"Calling fff_track_query with file_path = NULL, an unterminated buffer, or a path containing bytes that are not valid UTF-8 (common with non-UTF-8 filesystem encodings).","commonSituations":"Host editor passes a buffer name that is not valid UTF-8; caller passes an empty/unset path because no file is open; manual C string construction missing the NUL terminator.","solutions":["Ensure file_path is a valid, NUL-terminated UTF-8 C string.","Skip the tracking call when no file is selected instead of passing NULL.","Convert non-UTF-8 paths lossily or reject them in the host before calling.","Confirm the string buffer outlives the call."],"exampleFix":"// before\nfff_track_query(inst, query, NULL); // error\n// after\nif (file_path != NULL) { fff_track_query(inst, query, file_path); }","handlingStrategy":"validation","validationCode":"if file_path == nil or #file_path == 0 then return end","typeGuard":"local function is_trackable_path(p) return type(p) == 'string' and #p > 0 and vim.fn.filereadable(p) == 1 end","tryCatchPattern":"local ok, res = pcall(fff.track_query, inst, q, file_path)\nif not ok or res.is_err then log('tracking skipped') end","preventionTips":["Skip tracking when no file is open instead of passing NULL.","Ensure paths are valid UTF-8 before crossing the FFI boundary.","Keep string buffers alive for the duration of the call."],"tags":["ffi","utf-8","null-pointer","validation"],"backgroundTag":"null-argument","analyzedSha":"7f8537e70f0ea1210f9acbbfc4640141105cdc78","analyzedAt":"2026-09-10T07:26:53.407Z","contentChangedAt":"2026-09-10T07:26:53.407Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}