{
  "id": "go/cgo-char-array-null-termination",
  "signature": "panic: runtime error: cgo argument has Go pointer to Go pointer",
  "signature_zh": "恐慌：运行时错误：cgo参数包含指向Go指针的Go指针",
  "regex": "panic:\\ runtime\\ error:\\ cgo\\ argument\\ has\\ Go\\ pointer\\ to\\ Go\\ pointer",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Passing a Go slice or string to C as `char*` without null termination, causing C to read past bounds.",
  "root_cause_type": "generic",
  "root_cause_zh": "将Go切片或字符串作为`char*`传递给C时未添加空终止符，导致C读取越界。",
  "versions": [
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using `C.CString` but forgetting to free",
      "why_fails": "Memory leak, but the null termination is correct; this error is about pointer nesting.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Passing `&s[0]` directly",
      "why_fails": "Go string data is not null-terminated.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use `C.CString` which allocates a null-terminated C string",
      "success_rate": 0.95,
      "how": "cs := C.CString(\"hello\")\ndefer C.free(unsafe.Pointer(cs))\nC.printString(cs)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Manually append null byte and pin",
      "success_rate": 0.85,
      "how": "b := []byte(\"hello\\x00\")\nC.printString((*C.char)(unsafe.Pointer(&b[0])))",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}