zError
Returns the text associated with a zlib result code.
Full chapter and shared rules ↗767fa1407a7fe3d1 · Source at the matching commit ↗Read the function’s preconditions and results first. Expand the shared rules below for buffer and ownership requirements used throughout this API group.
const char * ZEXPORT zError(int err);
Returns the text associated with a zlib result code.
Domain Full type domain.
Pre Full type domain: every int, including its minimum and maximum values.
Post Returns a non-NULL pointer to the following NUL-terminated text.
err |
Text |
|---|---|
| 2 | need dictionary |
| 1 | stream end |
| -1 | file error |
| -2 | stream error |
| -3 | data error |
| -4 | insufficient memory |
| -5 | buffer error |
| -6 | incompatible version |
| 0 or any other value | empty string |
Effects Read-only. The result is borrowed immutable static storage; do not write or free it. No allocation, heap change or error return occurs. Values outside -6–2 are checked before index arithmetic, so both scalar extremes safely return empty text.
Back to the API manual · Contract conventions
Shared conditions and scope
API manual · Shared stream rules · Checksums
Use the buffer utilities when the complete input and output capacity are known at the call. They manage a temporary stream internally. Use the stream pages when you need incremental I/O, a different wrapper, a dictionary or explicit flush boundaries.
| Task | Entries |
|---|---|
| Compress a buffer | Choose a level, default level, size the destination |
| Decompress a buffer | Report input consumed, output only |
| Inspect the library | Version, compile flags, error text |
The focused contracts follow compress.c, uncompr.c, zutil.c and zlib.h in the default
LP64 Linux build. _z forms use z_size_t; plain forms use uLong. Both are 64-bit here.
Source readings are to confirm by proof. They do not narrow the registered targets in
Utilities.lean and
Queries.lean.
Calls.lean fixes translated arguments and results.
See contract conventions for domain/effect labels and
progress for proof status and remaining work.
The buffer utilities create and release a local stream with the zlib wrapper and default settings.
flowchart LR
B["compressBound"] --> C["compress / compress2"]
C --> Z["zlib stream"] --> U["uncompress / uncompress2"]
U --> D["decoded bytes"]
Common conventions
For buffer calls, the domain is restricted to valid memory: non-NULL sources cover the stated readable input; non-NULL destinations cover the stated writable capacity. Non-NULL length pointers name readable, writable scalar cells. Input, output and length cells are separate, including the two length cells when both occur. The caller keeps those objects live and does not modify them during the call. Each entry states its allowed NULL cases. Other invalid pointers are outside this scope. Decompression error handling needs no valid compressed-data assumption.
Common effects. Every in-scope call terminates without a fault. Buffer calls preserve input and memory outside the output and length cells. They write at most the original capacity. All internal allocations are released before return, including on allocation failure; no local stream or owned allocation is returned. Pointer-valued queries return borrowed immutable storage. These are contract requirements, not claims that the implementation proofs are complete.
Formal contract
ZlibF.Spec.Public.Goal.zError
Proof status: Registered proof · Evidence and remaining work
/-- `const char *zError(int err)`.
Every signed argument returns the public error text as static read-only storage.
Every heap is unchanged; no allocation, leak or runtime fault is permitted. -/
def Goal.zError : Prop :=
∀ (h : Heap) (err : Int32), ∃ p,
C.run (Zlib.Zutil.zError err) h = .ok (p, h) ∧ StaticString h p (errorText err.toInt)Related definitions and source ↗