From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/, /
Date: Fri, 23 Mar 2018 11:56:15 +0000 (UTC) [thread overview]
Message-ID: <1521806126.beb68b28d4694aa576d0e06fc37deb31d83cef80.grobian@gentoo> (raw)
commit: beb68b28d4694aa576d0e06fc37deb31d83cef80
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 23 11:55:26 2018 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Mar 23 11:55:26 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=beb68b28
getline: fix comparison of integers of different signs
Just use an int to store getline return, then ensure it is positive,
such that a cast to size_t is guaranteed to result in the same value.
libq/profile.c | 7 ++++---
qcache.c | 14 ++++++++------
qlop.c | 17 ++++++++++-------
qmerge.c | 14 ++++++++------
qsearch.c | 12 +++++++-----
quse.c | 29 ++++++++++++++++++-----------
6 files changed, 55 insertions(+), 38 deletions(-)
diff --git a/libq/profile.c b/libq/profile.c
index c954ba6..ad631a1 100644
--- a/libq/profile.c
+++ b/libq/profile.c
@@ -6,7 +6,8 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
{
FILE *fp;
int subdir_fd, fd;
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf;
/* Pop open this profile dir */
@@ -46,10 +47,10 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file,
}
buf = NULL;
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
char *s;
- rmspace_len(buf, linelen);
+ rmspace_len(buf, (size_t)linelen);
s = strchr(buf, '#');
if (s)
diff --git a/qcache.c b/qcache.c
index 7cd100e..0082e5b 100644
--- a/qcache.c
+++ b/qcache.c
@@ -220,7 +220,8 @@ qcache_read_cache_file(const char *filename)
char *buf;
FILE *f;
portage_cache *ret = NULL;
- size_t len, buflen, linelen;
+ int linelen;
+ size_t len, buflen;
if ((f = fopen(filename, "r")) == NULL)
goto err;
@@ -234,8 +235,8 @@ qcache_read_cache_file(const char *filename)
len = sizeof(*ret) + s.st_size + 1;
ret = xzalloc(len);
- while ((linelen = getline(&buf, &buflen, f)) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, f)) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
if (strncmp(buf, "DEPEND=", 7) == 0)
ret->DEPEND = xstrdup(buf + 7);
@@ -868,7 +869,8 @@ qcache_load_arches(const char *overlay)
{
FILE *fp;
char *filename, *s;
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf;
xasprintf(&filename, "%s/profiles/arch.list", overlay);
@@ -879,8 +881,8 @@ qcache_load_arches(const char *overlay)
archlist_count = 0;
arch_longest_len = 0;
buf = NULL;
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
if ((s = strchr(buf, '#')) != NULL)
*s = '\0';
diff --git a/qlop.c b/qlop.c
index f0c35b7..5be2ddd 100644
--- a/qlop.c
+++ b/qlop.c
@@ -232,7 +232,8 @@ show_emerge_history(int listflag, array_t *atoms, const char *logfile,
time_t start_time, time_t end_time)
{
FILE *fp;
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf, merged;
char *p, *q;
bool showit;
@@ -246,16 +247,17 @@ show_emerge_history(int listflag, array_t *atoms, const char *logfile,
}
buf = NULL;
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
if (linelen < 30)
continue;
- rmspace_len(buf, linelen);
+ rmspace_len(buf, (size_t)linelen);
if ((p = strchr(buf, ':')) == NULL)
continue;
*p = 0;
q = p + 3;
- /* Make sure there's leading white space and not a truncated string. #573106 */
+ /* Make sure there's leading white space and not a truncated
+ * string. #573106 */
if (p[1] != ' ' || p[2] != ' ')
continue;
@@ -331,7 +333,8 @@ static void
show_sync_history(const char *logfile, time_t start_time, time_t end_time)
{
FILE *fp;
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf, *p;
time_t t;
@@ -342,7 +345,7 @@ show_sync_history(const char *logfile, time_t start_time, time_t end_time)
buf = NULL;
/* Just find the finish lines. */
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
/* This cuts out like ~10% of the log. */
if (linelen < 35)
continue;
@@ -356,7 +359,7 @@ show_sync_history(const char *logfile, time_t start_time, time_t end_time)
continue;
p += 19;
- rmspace_len(buf, linelen);
+ rmspace_len(buf, (size_t)linelen);
t = (time_t)atol(buf);
if (t < start_time || t > end_time)
diff --git a/qmerge.c b/qmerge.c
index 1f75acc..960a9a4 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1653,7 +1653,8 @@ static int
parse_packages(queue *todo)
{
FILE *fp;
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf, *p;
struct pkg_t Pkg;
depend_atom *pkg_atom;
@@ -1665,8 +1666,8 @@ parse_packages(queue *todo)
repo[0] = '\0';
/* First consume the header with the common data. */
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
if (buf[0] == '\0')
break;
@@ -1785,7 +1786,8 @@ static queue *
qmerge_add_set_file(const char *dir, const char *file, queue *set)
{
FILE *fp;
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf, *fname;
/* Find the file to read */
@@ -1800,8 +1802,8 @@ qmerge_add_set_file(const char *dir, const char *file, queue *set)
/* Load each entry */
buf = NULL;
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
set = add_set(buf, set);
}
free(buf);
diff --git a/qsearch.c b/qsearch.c
index 1ebfccf..c2b2ebe 100644
--- a/qsearch.c
+++ b/qsearch.c
@@ -101,8 +101,9 @@ qsearch_ebuild_ebuild(int overlay_fd, const char *ebuild, const char *search_me,
}
char *buf = NULL;
- size_t buflen, linelen;
- while ((linelen = getline(&buf, &buflen, ebuildfp)) != -1) {
+ int linelen;
+ size_t buflen;
+ while ((linelen = getline(&buf, &buflen, ebuildfp)) >= 0) {
if (linelen <= search_len)
continue;
if (strncmp(buf, search_var, search_len) != 0)
@@ -194,10 +195,11 @@ int qsearch_main(int argc, char **argv)
continue;
}
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf = NULL;
- while ((linelen = getline(&buf, &buflen, fp)) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
if (!buf[0])
continue;
diff --git a/quse.c b/quse.c
index 81d99d8..ea8a326 100644
--- a/quse.c
+++ b/quse.c
@@ -82,7 +82,8 @@ static void
quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, char **argv)
{
#define NUM_SEARCH_FILES ARRAY_SIZE(search_files)
- size_t buflen, linelen;
+ int linelen;
+ size_t buflen;
char *buf, *p;
unsigned int i, f;
size_t s;
@@ -110,8 +111,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
if (fp[f] == NULL)
continue;
- while ((linelen = getline(&buf, &buflen, fp[f])) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, fp[f])) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
if (buf[0] == '#' || buf[0] == '\0')
continue;
@@ -119,7 +120,9 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
case 0: /* Global use.desc */
if (!strncmp(buf, argv[i], s))
if (buf[s] == ' ' && buf[s + 1] == '-') {
- printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf + s + 3);
+ printf(" %sglobal%s:%s%s%s: %s\n",
+ BOLD, NORM, BLUE, argv[i], NORM,
+ buf + s + 3);
goto skip_file;
}
break;
@@ -131,14 +134,17 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
if (!strncmp(p, argv[i], s)) {
if (p[s] == ' ' && p[s + 1] == '-') {
*p = '\0';
- printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p + s + 3);
+ printf(" %slocal%s:%s%s%s:%s%s%s %s\n",
+ BOLD, NORM, BLUE, argv[i], NORM,
+ BOLD, buf, NORM, p + s + 3);
}
}
break;
case 2: /* Architectures arch.list */
if (!strcmp(buf, argv[i])) {
- printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
+ printf(" %sarch%s:%s%s%s: %s architecture\n",
+ BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
goto skip_file;
}
break;
@@ -191,8 +197,8 @@ quse_describe_flag(const char *overlay, unsigned int ind, unsigned int argc, cha
/* Chop the trailing .desc for better display */
*p = '\0';
- while ((linelen = getline(&buf, &buflen, fp[0])) != -1) {
- rmspace_len(buf, linelen);
+ while ((linelen = getline(&buf, &buflen, fp[0])) >= 0) {
+ rmspace_len(buf, (size_t)linelen);
if (buf[0] == '#' || buf[0] == '\0')
continue;
@@ -231,7 +237,8 @@ int quse_main(int argc, char **argv)
char buf1[_Q_PATH_MAX];
char buf2[_Q_PATH_MAX];
- size_t ebuildlen, linelen;
+ int linelen;
+ size_t ebuildlen;
char *ebuild;
const char *search_var = NULL;
@@ -279,11 +286,11 @@ int quse_main(int argc, char **argv)
int overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH);
ebuild = NULL;
- while ((linelen = getline(&ebuild, &ebuildlen, fp)) != -1) {
+ while ((linelen = getline(&ebuild, &ebuildlen, fp)) >= 0) {
FILE *newfp;
int fd;
- rmspace_len(ebuild, linelen);
+ rmspace_len(ebuild, (size_t)linelen);
fd = openat(overlay_fd, ebuild, O_RDONLY|O_CLOEXEC);
if (fd < 0)
next reply other threads:[~2018-03-23 11:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 11:56 Fabian Groffen [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-06-27 19:19 [gentoo-commits] proj/portage-utils:master commit in: libq/, / Fabian Groffen
2024-03-29 10:57 Fabian Groffen
2024-01-02 7:57 Fabian Groffen
2023-02-07 8:25 Fabian Groffen
2023-02-07 8:10 Fabian Groffen
2021-08-16 13:23 Fabian Groffen
2020-02-21 8:18 Fabian Groffen
2020-01-05 13:28 Fabian Groffen
2020-01-02 11:19 Fabian Groffen
2020-01-01 19:52 Fabian Groffen
2019-12-31 9:05 Fabian Groffen
2019-12-30 17:24 Fabian Groffen
2019-12-29 13:26 Fabian Groffen
2019-12-27 16:57 Fabian Groffen
2019-07-13 10:04 Fabian Groffen
2019-06-19 10:44 Fabian Groffen
2019-06-05 9:15 Fabian Groffen
2019-05-09 20:19 Fabian Groffen
2019-05-05 18:13 Fabian Groffen
2019-04-28 15:20 Fabian Groffen
2019-03-27 20:18 Fabian Groffen
2019-03-27 10:55 Fabian Groffen
2019-03-22 9:57 Fabian Groffen
2019-03-19 20:32 Fabian Groffen
2019-03-19 20:32 Fabian Groffen
2019-03-09 18:58 Fabian Groffen
2016-12-29 2:25 Mike Frysinger
2016-11-26 23:17 Mike Frysinger
2015-11-28 2:44 Mike Frysinger
2015-02-24 1:26 Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1521806126.beb68b28d4694aa576d0e06fc37deb31d83cef80.grobian@gentoo \
--to=grobian@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox