Skip to content
Back to skills

Map

ASecurity

Map nil safety - read OK, write panics

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

Security analysis

A100/100

Scanned February 12, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Map?

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

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

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-map
description: Map nil safety - read OK, write panics
---

# Map Nil Safety

## Problem
Reading from nil map returns zero value. Writing to nil map panics.

## Pattern

### WRONG - Write to nil map
```go
var m map[string]int  // nil map
m["key"] = 42         // PANIC: assignment to entry in nil map
```

### CORRECT - Initialize with make
```go
m := make(map[string]int)
m["key"] = 42  // OK
```

### Reading is Safe
```go
var m map[string]int  // nil map
v := m["key"]         // OK, v = 0 (zero value)
v, ok := m["key"]     // OK, v = 0, ok = false
```

## Quick Fix
- [ ] Always initialize maps with make() before writing
- [ ] Check if map is nil before range/write
- [ ] Reading from nil map is safe but returns zero values

## Defensive Pattern
```go
if m == nil {
    m = make(map[string]int)
}
m["key"] = 42
```

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.