{"record":{"id":"98a97d142d26882f","repo":"wasmerio/wasmer","slug":"wasm-valtype-kind-argument-is-a-null-pointer","errorCode":null,"errorMessage":"`wasm_valtype_kind: argument is a null pointer","messagePattern":"`wasm_valtype_kind: argument is a null pointer","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/c-api/src/wasm_c_api/types/value.rs","lineNumber":98,"sourceCode":"        }\n    }\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option<Box<wasm_valtype_t>> {\n    let kind_enum = kind.try_into().ok()?;\n    let valtype = wasm_valtype_t { valkind: kind_enum };\n\n    Some(Box::new(valtype))\n}\n\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn wasm_valtype_delete(_valtype: Option<Box<wasm_valtype_t>>) {}\n\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn wasm_valtype_kind(valtype: Option<&wasm_valtype_t>) -> wasm_valkind_t {\n    valtype\n        .expect(\"`wasm_valtype_kind: argument is a null pointer\")\n        .valkind as wasm_valkind_t\n}\n","sourceCodeStart":80,"sourceCodeEnd":101,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/c-api/src/wasm_c_api/types/value.rs#L80-L101","documentation":"wasm_valtype_kind is part of the C API and expects a non-null pointer to a wasm_valtype_t. Passing NULL is undefined behavior in the C API contract, so the Rust implementation panics with this message via .expect(). It is a defensive guard against misuse of the C ABI.","triggerScenarios":"Calling wasm_valtype_kind(NULL) from C/C++ code, e.g. after wasm_valtype_new failed or a valtype was already deleted/freed and the pointer set to null.","commonSituations":"C embedders building Wasm types programmatically; uninitialized or double-freed valtype pointers; binding generators passing optional/null values through.","solutions":["Check the pointer for NULL before calling wasm_valtype_kind","Ensure wasm_valtype_new succeeded and the valtype was not deleted before use","Recreate the valtype if it was consumed or freed","Enable address sanitizer/valgrind to find where the pointer became null"],"exampleFix":"// before\nwasm_valkind_t k = wasm_valtype_kind(valtype);\n// after\nif (valtype != NULL) {\n    wasm_valkind_t k = wasm_valtype_kind(valtype);\n} else {\n    // handle missing valtype\n}","handlingStrategy":"type-guard","validationCode":"// C caller\nif (valtype == NULL) { /* handle error */ return 0; }","typeGuard":"// in Rust bindings\nfn is_valid(valtype: Option<&wasm_valtype_t>) -> bool { valtype.is_some() }","tryCatchPattern":"// Wrap C-API FFI calls at the binding layer\nlet kind = std::panic::catch_unwind(|| unsafe { wasm_valtype_kind(valtype) })\n    .map_err(|_| anyhow::anyhow!(\"null valtype passed to wasm_valtype_kind\"))?;","preventionTips":["Always null-check C API arguments before calling wasm_* functions","Never use a valtype after wasm_valtype_delete","Check allocation results from wasm_valtype_new before use","Use RAII wrappers in C++ so pointers cannot dangle to null"],"tags":["c-api","null-pointer","panic","wasm"],"backgroundTag":"null-pointer-argument","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}