lkml.org 
[lkml]   [2013]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] Fix wrong EOF compare
Date
getc returns "int" so EOF could be -1 but storing getc's return
value to char directly makes the vaule to 255 so below condition
is always false.

It happens in my ARM system so loop is not ended, then segfaulted.
This patch fixes it.

*curr = getc(fin); // *curr = 255
if (*curr == EOF) return -1; // if ( 255 == -1)

Cc: Mel Gorman <mgorman@suse.de>
Cc: Andy Whitcroft <apw@shadowen.org>
Cc: Alexander Nyberg <alexn@dsv.su.se>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
Documentation/page_owner.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/page_owner.c b/Documentation/page_owner.c
index f0156e1..b777fb6 100644
--- a/Documentation/page_owner.c
+++ b/Documentation/page_owner.c
@@ -32,12 +32,14 @@ int read_block(char *buf, FILE *fin)
{
int ret = 0;
int hit = 0;
+ int vaule;
char *curr = buf;

for (;;) {
- *curr = getc(fin);
- if (*curr == EOF) return -1;
+ value = getc(fin);
+ if (value == EOF) return -1;

+ *curr = value;
ret++;
if (*curr == '\n' && hit == 1)
return ret - 1;
--
1.7.9.5


\
 
 \ /
  Last update: 2013-01-10 07:41    [W:0.086 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site