Skip to content
Back to skills

Pointer

ASecurity

Pointer receiver nil safety - methods can be called on nil

  • 3 stars
  • 0 votes
  • 0 copies
  • 16 views
  • Added February 7, 2026
developmentgo

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add JamesPrial/claudefiles --skill pointer --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pointer?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pointer
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jamesprial-pointer/badge)](https://www.skillsdirectory.com/skills/jamesprial-pointer)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: go-nil-pointer
description: Pointer receiver nil safety - methods can be called on nil
---

# Pointer Receiver Nil

## Problem
Methods with pointer receivers can be called on nil. Must handle nil receiver.

## Pattern

### WRONG - Assume receiver is non-nil
```go
type Tree struct {
    Value int
    Left  *Tree
}

func (t *Tree) Sum() int {
    return t.Value + t.Left.Sum()  // PANIC if t or t.Left is nil
}
```

### CORRECT - Handle nil receiver
```go
type Tree struct {
    Value int
    Left  *Tree
    Right *Tree
}

func (t *Tree) Sum() int {
    if t == nil {
        return 0  // Nil tree has sum of 0
    }
    return t.Value + t.Left.Sum() + t.Right.Sum()
}

// Now safe to call
var tree *Tree  // nil
sum := tree.Sum()  // Returns 0, no panic
```

## Use Cases
Nil receiver pattern enables elegant recursive algorithms and optional behavior.

## Quick Fix
- [ ] Check if receiver is nil at method start
- [ ] Define sensible zero behavior for nil receiver
- [ ] Document whether methods are nil-safe

## When NOT to Use
If nil receiver doesn't make semantic sense, panic early with clear message.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.