This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=4682652aabe4423177f26982c613e2e79765a393 commit 4682652aabe4423177f26982c613e2e79765a393 Author: Guillem Jover <[email protected]> AuthorDate: Wed Jul 10 23:20:52 2024 +0200 Check for >= 0 instead of != -1 for syscall return values While checking for != -1 is correct for all these calls, as that is what the non-error condition is specified to return, this can confuse static analyzers where these might consider other negative return values as unhandled and emit bogus potential overflow or underflow conditions. Make these checks >= 0, which is shorter, also correct, and should pacify static analyzers. Changelog: internal --- lib/dpkg/buffer.c | 2 +- lib/dpkg/db-fsys-files.c | 2 +- lib/dpkg/dbmodify.c | 4 ++-- src/deb/extract.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/dpkg/buffer.c b/lib/dpkg/buffer.c index ed05f4b4a..fbacb3e56 100644 --- a/lib/dpkg/buffer.c +++ b/lib/dpkg/buffer.c @@ -267,7 +267,7 @@ buffer_skip(struct buffer_data *input, off_t limit, struct dpkg_error *err) switch (input->type) { case BUFFER_READ_FD: - if (lseek(input->arg.i, limit, SEEK_CUR) != -1) + if (lseek(input->arg.i, limit, SEEK_CUR) >= 0) return limit; if (errno != ESPIPE) return dpkg_put_errno(err, _("failed to seek")); diff --git a/lib/dpkg/db-fsys-files.c b/lib/dpkg/db-fsys-files.c index 244ef0a0b..3d7c4fc72 100644 --- a/lib/dpkg/db-fsys-files.c +++ b/lib/dpkg/db-fsys-files.c @@ -247,7 +247,7 @@ pkg_files_optimize_load(struct pkg_array *array) listfile = pkg_infodb_get_file(pkg, &pkg->installed, LISTFILE); fd = open(listfile, O_RDONLY | O_NONBLOCK); - if (fd != -1) { + if (fd >= 0) { posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED); close(fd); } diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c index a88ab4ad2..7182cdbad 100644 --- a/lib/dpkg/dbmodify.c +++ b/lib/dpkg/dbmodify.c @@ -282,7 +282,7 @@ modstatdb_lock(void) ohshit(_("you do not have permission to lock the dpkg database directory %s"), dpkg_db_get_dir()); - if (frontendlockfd != -1) + if (frontendlockfd >= 0) file_lock(&frontendlockfd, FILE_LOCK_NOWAIT, frontendlockfile, _("dpkg frontend lock")); file_lock(&dblockfd, FILE_LOCK_NOWAIT, lockfile, @@ -294,7 +294,7 @@ modstatdb_unlock(void) { /* Unlock. */ pop_cleanup(ehflag_normaltidy); - if (frontendlockfd != -1) + if (frontendlockfd >= 0) pop_cleanup(ehflag_normaltidy); dblockfd = -1; diff --git a/src/deb/extract.c b/src/deb/extract.c index 8b78a7eab..08b281564 100644 --- a/src/deb/extract.c +++ b/src/deb/extract.c @@ -364,7 +364,7 @@ extracthalf(const char *debar, const char *dir, } subproc_reap(c2, _("<decompress>"), SUBPROC_NOPIPE); - if (c1 != -1) + if (c1 >= 0) subproc_reap(c1, _("paste"), 0); if (version.major == 0 && admininfo) { /* Handle the version as a float to preserve the behavior of old code, -- Dpkg.Org's dpkg

