{"record":{"id":"32de55f0bc43c70f","repo":"dmtrKovalenko/fff","slug":"opts-is-null","errorCode":null,"errorMessage":"opts is null","messagePattern":"opts is null","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fff-c/src/lib.rs","lineNumber":185,"sourceCode":"\n/// Create a new file finder instance from a versioned [`FffCreateOptions`] struct.\n///\n/// Populate the struct, set `version` to [`FFF_CREATE_OPTIONS_VERSION`], pass by\n/// pointer. New fields are only appended; older `version` values keep working.\n/// FFI bindings needing struct-by-value should use [`fff_create_instance_with_value`].\n///\n/// `opts.base_path` is required (non-NULL, non-empty). Zero `cache_budget_*`\n/// values are auto-computed from repo size after the initial scan.\n///\n/// ## Safety\n/// * `opts` must be a valid pointer to an `FffCreateOptions` whose `version`\n///   is in the range `1..=FFF_CREATE_OPTIONS_VERSION`.\n/// * All string pointers inside `opts` must be valid null-terminated UTF-8\n///   or NULL.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn fff_create_instance_with(opts: *const FffCreateOptions) -> *mut FffResult {\n    if opts.is_null() {\n        return FffResult::err(\"opts is null\");\n    }\n    let opts = unsafe { &*opts };\n    if opts.version == 0 || opts.version > FFF_CREATE_OPTIONS_VERSION {\n        return FffResult::err(&format!(\n            \"Unsupported FffCreateOptions version {} (library understands up to {})\",\n            opts.version, FFF_CREATE_OPTIONS_VERSION\n        ));\n    }\n\n    let base_path_str = match unsafe { cstr_to_str(opts.base_path) } {\n        Some(s) if !s.is_empty() => s.to_string(),\n        _ => return FffResult::err(\"opts.base_path is null or empty\"),\n    };\n\n    if let Some(log_path) = unsafe { optional_cstr(opts.log_file_path) } {\n        let level = unsafe { optional_cstr(opts.log_level) };\n        if let Err(e) = fff::log::init_tracing(log_path, level, None) {\n            return FffResult::err(&format!(\"Failed to init tracing: {}\", e));","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/dmtrKovalenko/fff/blob/7f8537e70f0ea1210f9acbbfc4640141105cdc78/crates/fff-c/src/lib.rs#L167-L203","documentation":"fff_create_instance_with requires a pointer to an FffCreateOptions struct. A null pointer carries no configuration, so the call fails fast instead of dereferencing null. Use fff_create_instance if you want defaults with no options struct.","triggerScenarios":"Calling fff_create_instance_with(NULL); a binding that passes a zero-initialized options pointer variable; forgetting to allocate the struct in C or pass the options object in a higher-level binding.","commonSituations":"Hand-written FFI bindings that drop the options argument; code paths that conditionally build options and pass undefined/null; migrating from fff_create_instance and using the wrong entry point.","solutions":["Pass a valid FffCreateOptions pointer with version set to FFF_CREATE_OPTIONS_VERSION.","Use fff_create_instance(base_path) instead if no options struct is needed.","In bindings, construct the options object/struct explicitly before calling.","Check for null in the binding layer and raise a clear error early."],"exampleFix":"// before\nfff_create_instance_with(null);\n// after\nFffCreateOptions opts = { .version = FFF_CREATE_OPTIONS_VERSION, .base_path = \"/repo\" };\nfff_create_instance_with(&opts);","handlingStrategy":"validation","validationCode":"if (!opts) throw new Error('fff: options object required by fff_create_instance_with');","typeGuard":"function isValidCreateOptions(o) { return o !== null && o !== undefined && o.version >= 1 && typeof o.base_path === 'string' && o.base_path.length > 0; }","tryCatchPattern":"if (!opts) return useDefaultInstance(); // or throw\nconst res = fff_create_instance_with(buildOptsStruct(opts));\nif (!res.ok) throw new Error(res.error);","preventionTips":["Prefer fff_create_instance when defaults suffice.","Always allocate/populate the options struct before the call.","Null-check optional options before passing pointers.","Centralize options construction in one helper."],"tags":["ffi","rust","null-pointer"],"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"}