Skip to content

Null pointer warning in adler.c (static analysis) #1143

@irwir

Description

@irwir

zlib/adler32.c

Lines 69 to 71 in 2896db6

/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
adler += buf[0];

Suspicious to code analyzer is dereferencing buf while the pointer is checked for null later.

The function declared as ZEXPORT presumably could be called by user with these arguments: adler32_z(0, NULL, 1).
Code could be made safe by moving the NULL check up, before the quoted code.
The point of keeping it fast is a small excuse, because making a call for every single byte is certainly not about speed, while the additional check needs only two instructions (at least, for x86/x64).

The warning could be suppressed by replacing buf == Z_NULL with len == 0, but the code would be less safe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions