diff options
author | Fabian Groffen <grobian@gentoo.org> | 2018-03-23 12:55:26 +0100 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2018-03-23 12:55:26 +0100 |
commit | beb68b28d4694aa576d0e06fc37deb31d83cef80 (patch) | |
tree | 610858617ea2e86ccb75c85f1faf6af0c29579eb /qlop.c | |
parent | is_prelink_elf: squash unused variable warning (diff) | |
download | portage-utils-beb68b28d4694aa576d0e06fc37deb31d83cef80.tar.gz portage-utils-beb68b28d4694aa576d0e06fc37deb31d83cef80.tar.bz2 portage-utils-beb68b28d4694aa576d0e06fc37deb31d83cef80.zip |
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.
Diffstat (limited to 'qlop.c')
-rw-r--r-- | qlop.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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) |