---
title: "negative-length-capacity-comparison"
description: "Detect checks for negative len or cap results."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# negative-length-capacity-comparison

**Default severity:** `warning`

The predeclared `len` and `cap` functions always return non-negative values, so
testing whether either result is below zero can never succeed.

## Bad

```go
if len(values) < 0 { unreachable() }
```

## Good

```go
if len(values) == 0 { handleEmpty() }
```

Source: https://strider.gempir.com/analyzers/negative-length-capacity-comparison/index.mdx
