[pacman-dev] [PATCH] Store fgetc output as an int.

Allan McRae allan at archlinux.org
Mon Aug 12 07:12:01 EDT 2013


Bug exposed on ARM when char is unsigned resulting in the comparison
to EOF always failing.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 src/pacman/pacman.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 5ce8747..24fd57f 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -830,13 +830,15 @@ int main(int argc, char *argv[])
 			int target_found = 0;
 			size_t current_size = PATH_MAX;
 			char *vdata, *line = malloc(current_size);
+			int c;
 
 			/* remove the '-' from the list */
 			pm_targets = alpm_list_remove_str(pm_targets, "-", &vdata);
 			free(vdata);
 
 			i = 0;
-			while((line[i] = (char)fgetc(stdin)) != EOF) {
+			while((c = fgetc(stdin)) != EOF) {
+				line[i] = (char)c;
 				if(isspace((unsigned char)line[i])) {
 					/* avoid adding zero length arg when multiple spaces separate args */
 					if(i > 0) {
-- 
1.8.3.4



More information about the pacman-dev mailing list