From 049c6b69562f81676a01c9fa5f4982baa3d465ee Mon Sep 17 00:00:00 2001 From: Jozkar Date: Thu, 31 Mar 2016 21:36:10 +0200 Subject: [PATCH 1/2] Scanf has been replaced by getline --- src/client/client.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client/client.c b/src/client/client.c index 7a8fed4..44fce4b 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -528,15 +528,19 @@ int rpm_process(GSList *install, GSList *update, GSList *erase) { int question(char* question, int possibilities) { int status = NO, repeat = 1; - char answer; + char *answer = NULL, letter; switch(possibilities) { case YES_NO: while(repeat) { rds_log(logQUESTION, "%s\n[y/n]: ", question); - scanf("%c", &answer); + if(getline(&answer, &size, stdin) == -1){ + // TODO error message after log reimpmelentation + }else{ + letter = answer[0]; + } - switch(answer) + switch(letter) { case 'y': status = YES; @@ -549,7 +553,6 @@ int question(char* question, int possibilities) { default: rds_log(logWARNING, "Unsupported answer. You should choose y for yes or n for no.\n"); - scanf("%c", &answer); //eliminating enter break; } } @@ -559,9 +562,13 @@ int question(char* question, int possibilities) { while(repeat) { rds_log(logQUESTION, "%s\n[y/n/d]: ", question); - scanf("%c", &answer); - - switch(answer) + if(getline(&answer, &size, stdin) == -1){ + // TODO error message after log reimpmelentation + }else{ + letter = answer[0]; + } + + switch(letter) { case 'y': status = YES; @@ -579,7 +586,6 @@ int question(char* question, int possibilities) { default: rds_log(logWARNING, "Unsupported answer. You should choose y for yes, n for no or d for download only.\n"); - scanf("%c", &answer); //eliminating enter break; } } From 2740d41051048b2a638d30904d0f9b38e03d7a70 Mon Sep 17 00:00:00 2001 From: Jozkar Date: Thu, 7 Apr 2016 09:31:13 +0200 Subject: [PATCH 2/2] Memory leek fixed --- src/client/client.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/client.c b/src/client/client.c index 44fce4b..b9cf5a2 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -592,5 +592,10 @@ int question(char* question, int possibilities) { break; } + if(answer != NULL){ + + free(answer); + } + return status; }