# std: restrict mem.span\(\) and mem.len\(\) to sentinel terminated pointers · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/23b7d28896609e3f01765730599119baf53a56c9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 23b7d28896609e3f01765730599119baf53a56c9

Requested commit: 23b7d28896609e3f01765730599119baf53a56c9

Commit: 23b7d28896609e3f01765730599119baf53a56c9

Tree: cebad2d68d4c0a3d7059f181af6c2b7e1fff0116

Author: Isaac Freund

Committer: Andrew Kelley

## Message

```
std: restrict mem.span() and mem.len() to sentinel terminated pointers

These functions are currently footgunny when working with pointers to
arrays and slices. They just return the stated length of the array/slice
without iterating and looking for the first sentinel, even if the
array/slice is a sentinel terminated type.

From looking at the quite small list of places in the standard
library/compiler that this change breaks existing code, the new code
looks to be more readable in all cases.

The usage of std.mem.span/len was totally unneeded in most of the cases
affected by this breaking change.

We could remove these functions entirely in favor of other existing
functions in std.mem such as std.mem.sliceTo(), but that would be a
somewhat nasty breaking change as std.mem.span() is very widely used for
converting sentinel terminated pointers to slices. It is however not at
all widely used for anything else.

Therefore I think it is better to break these few non-standard and
potentially incorrect usages of these functions now and at some later
time, if deemed worthwhile, finally remove these functions.

If we wait for at least a full release cycle so that everyone adapts to
this change first, updating for the removal could be a simple find and
replace without needing to worry about the semantics.

```

## Parents

- [7c2ba950a758b86893bfbe73521b29895f7ac4f0](https://git.cafe/gitcafe/zig/commit/7c2ba950a758b86893bfbe73521b29895f7ac4f0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/23b7d28896609e3f01765730599119baf53a56c9?format=markdown)
