* src/arscan.c (ar_scan): Avoid sign comparison warnings

Pacify 12.2.1 20220819 (Red Hat 12.2.1-2) -Wsign-compare by checking
the readbuf() return explicitly for errors then casting from ssize_t.
Initial patch provided by Paul Eggert <eggert@cs.ucla.edu>.
This commit is contained in:
Paul Smith 2022-10-02 18:34:07 -04:00
parent ae80eefe65
commit ca92d83cde

View File

@ -716,12 +716,12 @@ ar_scan (const char *archive, ar_member_func_t function, const void *arg)
const char* err;
unsigned int name_len = make_toui (name + 3, &err);
if (err || name_len == 0 || name_len > PATH_MAX)
if (err || name_len == 0 || name_len >= MIN (PATH_MAX, INT_MAX))
goto invalid;
name = alloca (name_len + 1);
nread = readbuf (desc, name, name_len);
if (nread != name_len)
if (nread < 0 || (unsigned int) nread != name_len)
goto invalid;
name[name_len] = '\0';